# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
258020 | Vladikus004 | Kisik (COCI19_kisik) | C++14 | 1488 ms | 67924 KiB |
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 inf 2e9
#define ff first
#define ss second
#define int long long
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
const int N = 1000000 + 3;
int n, k, cur;
pii a[N];
vector <int> mxs;
multiset <int> ms;
bool cmp(pii a, pii b){
return a.ss < b.ss;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
cin >> n >> k;
for (int i = 0; i < n; i++){
cin >> a[i].ff >> a[i].ss;
mxs.push_back(a[i].ss);
}
sort(a, a + n, cmp);
sort(all(mxs));
mxs.resize(unique(all(mxs)) - mxs.begin());
int j = 0;
ll ans = inf * 1LL * inf;
for (int i = 0; i < mxs.size(); i++){
while (j < n && a[j].ss <= mxs[i]){
if (ms.size() < k) {
ms.insert(a[j].ff);
cur += a[j].ff;
}else
if (*ms.rbegin() > a[j].ff){
cur -= *ms.rbegin();
ms.erase(ms.lower_bound(*ms.rbegin()));
cur += a[j].ff;
ms.insert(a[j].ff);
}
j++;
}
if (ms.size() == k){
ans = min(ans, cur * 1LL * mxs[i]);
}
}
cout << ans;
}
Compilation message (stderr)
# | 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... |