You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
666 B
C++
28 lines
666 B
C++
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
const int N = 3e5 + 50;
|
|
pair<int, int> a[N];
|
|
int main()
|
|
{
|
|
int n, k;
|
|
scanf("%d%d", &n, &k);
|
|
for (int i = 0; i < n; i++)
|
|
scanf("%d%d", &a[i].second, &a[i].first);
|
|
sort(a, a + n);
|
|
multiset<int> lens;
|
|
long long sum = 0, ans = 0;
|
|
for (int i = n - 1; i >= 0; i--)
|
|
{
|
|
lens.insert(a[i].second);
|
|
sum += a[i].second;
|
|
while (lens.size() > k)
|
|
{
|
|
auto ite = lens.begin();
|
|
sum -= *ite;
|
|
lens.erase(ite);
|
|
}
|
|
ans = max(ans, sum * a[i].first);
|
|
}
|
|
printf("%lld", ans);
|
|
return 0;
|
|
} |