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>
#define pii pair<int,int>
#define ft first
#define sd second
using namespace std;
typedef long long ll;
const int N = 1000100;
const ll OO = 1e18;
priority_queue<int> st;
pii a[N];
int n, k;
ll sm = 0ll, ans = OO;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i].sd >> a[i].ft;
sort(a, a + n);
for (int i = 0; i < n; i++){
st.push(a[i].sd);
sm += a[i].sd;
if (i >= k){
sm -= st.top();
st.pop();
}
if (i + 1 >= k)
ans = min(ans, ll(a[i].ft) * sm);
}
cout << ans;
return 0;
}
# | 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... |