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 ll long long
#define fi first
#define se second
#define pb push_back
const int mod=998244353, maxn=1e6+5;
int n, k;
pair<ll, ll> a[maxn];
priority_queue<ll> pq;
ll tot, ans;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> k;
for(int i=1; i<=n; i++) cin >> a[i].se >> a[i].fi;
sort(a+1, a+n+1);
for(int i=1; i<=k; i++) {
pq.push(a[i].se);
tot+=a[i].se;
}
ans=a[k].fi*tot;
for(int i=k+1; i<=n; i++) {
if(a[i].se<pq.top()) {
tot-=pq.top()-a[i].se;
pq.pop();
pq.push(a[i].se);
}
ans=min(ans, a[i].fi*tot);
}
cout << ans << '\n';
}
# | 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... |