This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define w first
#define h second
typedef pair<int, int> rect;
const int N = 1e6;
bool cmp(rect r1, rect r2) {
return r1.h < r2.h;
}
rect b[N];
priority_queue<int> wd;
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
for(int i = 0; i < n; i++) cin >> b[i].w >> b[i].h;
sort(b, b+n, cmp);
int ans, temp = 0;
for(int i = 0; i < k-1; i++) {
temp += b[i].w;
wd.push(b[i].w);
}
ans = (temp + b[k-1].w) * b[k-1].h;
for(int i = k; i < n; i++) {
temp += b[i-1].w;
wd.push(b[i-1].w);
temp -= wd.top();
wd.pop();
int s = (temp + b[i].w) * b[i].h;
ans = min(ans, s);
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |