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;
using ll = long long;
void output(bool yes){yes ? cout << "Yes" << "\n" : cout << "No" << "\n";}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int n,k;
cin >> n >> k;
vector <pair<ll,ll>> v(n);
for(int i = 0;i < n;i++){
cin >> v[i].second >> v[i].first;
}
std::sort(v.begin(), v.end());
multiset <ll> ml;
ll sum = 0;
for(int i = 0;i < k;i++){
ml.insert(v[i].second);
sum += v[i].second;
}
ll res = sum * v[k-1].first;
auto it = ml.end();
it--;
for(int i = k;i < n;i++){
if(v[i].second < *it){
sum = sum + v[i].second - *it;
ml.insert(v[i].second);
it--;
res = min(res,sum * v[i].first);
}
}
cout << res << "\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... |