# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
198836 | ZwariowanyMarcin | Kisik (COCI19_kisik) | C++14 | 1637 ms | 65912 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 fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define LL long long
#define ld long double
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define boost cin.tie(0), ios_base::sync_with_stdio(0);
using namespace std;
const int nax = 1000100;
int n, k;
pair <int, int> x[nax];
multiset <int> s;
vector <int> vec;
LL sum = 0;
LL ans = 1e18 + 111;
void add(int val) {
sum += val;
s.insert(val);
if (ss(s) >= k) {
sum -= *--s.end();
s.erase(--s.end());
}
}
int main() {
scanf ("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) {
scanf ("%d%d", &x[i].se, &x[i].fi);
}
sort (x + 1, x + n + 1);
for (int i = 1; i <= n;) {
vec.clear();
int j = i;
while (j <= n && x[i].fi == x[j].fi) {
vec.pb(x[j].se);
j++;
}
sort(vec.begin(), vec.end());
for (int j = 1; j < ss(vec); ++j)
add(vec[j]);
if (ss(s) == k - 1)
ans = min(ans, 1LL * x[i].fi * (sum + x[i].se));
add(vec[0]);
i = j;
}
printf ("%lld", ans);
return 0;
}
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... |