| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 263245 | keko37 | Cake 3 (JOI19_cake3) | C++14 | 4073 ms | 9848 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>
using namespace std;
typedef long long llint;
typedef pair <llint, llint> pi;
const int MAXN = 200005;
const llint INF = 1000000000000000000LL;
llint n, m, sum, sol = -INF;
pi p[MAXN];
multiset <llint> st;
vector <int> v;
bool cmp (pi a, pi b) {
return a.second < b.second;
}
void init () {
st.clear();
sum = 0;
}
void ubaci (llint val) {
st.insert(val);
sum += val;
if (st.size() > m - 2) {
sum -= *st.begin();
st.erase(st.begin());
}
}
llint calc (int j) {
init();
llint res = -INF;
int ind = -1;
for (int i = j - 1; i >= 0; i--) {
if (st.size() == m - 2) {
llint tmp = sum + p[i].first + p[i].second;
if (tmp > res) {
res = tmp;
ind = i;
}
}
ubaci(p[i].first);
}
//cout << "bla " << ind << " " << j << " " << res << endl;
v.push_back(ind);
return res;
}
bool check () {
for (int i = 1; i < v.size(); i++) {
if (v[i] < v[i - 1]) return 0;
}
return 1;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second;
p[i].second *= 2;
}
sort(p, p + n, cmp);
for (int j = m - 1; j < n; j++) {
sol = max(sol, calc(j) + p[j].first - p[j].second);
}
cout << sol;
if (!check()) cout << "RIP";
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... | ||||
