using
System;
using
System.Collections.Generic;
public
class
GFG {
public
static
int
Comparator(KeyValuePair<
int
,
int
> p1,
KeyValuePair<
int
,
int
> p2)
{
if
(p1.Value > p2.Value)
return
-1;
return
1;
}
public
static
int
FindMaxRating(
int
N,
int
[] Point,
int
[] Upvote,
int
K)
{
List<KeyValuePair<
int
,
int
> > vec
=
new
List<KeyValuePair<
int
,
int
> >();
for
(
int
i = 0; i < N; i++) {
vec.Add(
new
KeyValuePair<
int
,
int
>(Point[i],
Upvote[i]));
}
vec.Sort(Comparator);
SortedSet<
int
> pq =
new
SortedSet<
int
>();
int
total_points = 0, max_rating = 0;
for
(
int
i = 0; i < K; i++) {
total_points = total_points + vec[i].Key;
max_rating = Math.Max(
max_rating, total_points * vec[i].Value);
pq.Add(vec[i].Key);
}
for
(
int
i = K; i < N; i++) {
if
(pq.Min < vec[i].Key) {
total_points
= total_points - pq.Min + vec[i].Key;
max_rating
= Math.Max(max_rating,
total_points * vec[i].Value);
pq.Remove(pq.Min);
pq.Add(vec[i].Key);
}
}
return
max_rating;
}
static
public
void
Main()
{
int
[] Point = { 2, 10, 3, 1, 5, 8 };
int
[] Upvote = { 5, 4, 3, 9, 7, 2 };
int
N = Point.Length;
int
K = 2;
Console.WriteLine(
"Maximum Rating of Coding Contest is: "
+ FindMaxRating(N, Point, Upvote, K));
}
}