QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#109554 | #71. Cake 3 | bashkort# | 0 | 0ms | 3832kb | C++20 | 1.4kb | 2023-05-29 18:16:20 | 2024-05-31 13:47:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<ll> V(n), C(n), V_(n), C_(n);
for (int i = 0; i < n; ++i) {
cin >> V[i] >> C[i];
C[i] *= 2;
}
vector<int> ord(n);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int i, int j) {
return C[i] < C[j];
});
V_ = V, C_ = C;
for (int i = 0; i < n; ++i) {
C[i] = C_[ord[i]];
V[i] = V_[ord[i]];
}
auto solve = [&](ll penalty) { // siuuuuu
pair<ll, int> ans{-3e18, -1};
pair<ll, int> dp{-3e18, -1};
for (int i = 0; i < n; ++i) {
pair<ll, int> now = {dp.first + V[i] - C[i] - penalty, dp.second - 1};
ans = max(ans, now);
now = {dp.first + V[i] - penalty, dp.second - 1};
dp = max({dp, pair{V[i] + C[i] - penalty, -1}, now});
}
return pair{ans.first, -ans.second};
};
ll lo = -3e12, hi = 3e12;
while (lo + 1 < hi) {
ll mid = (lo + hi) / 2;
auto [dp, mink] = solve(mid);
if (mink <= k) {
hi = mid;
} else {
lo = mid;
}
}
auto [dp, mink] = solve(hi);
cout << dp + k * hi << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 0ms
memory: 3820kb
input:
100 32 671208774 266481733 115497791 342597239 326245300 76223942 528973483 754205900 437996819 995535247 100582194 42402057 771100621 351934207 89058009 81951602 768935397 186435060 842907845 376386254 187943947 59424920 997369107 493642356 455078419 68850493 542835555 938351581 970171972 611243076...
output:
25580474644
result:
ok single line: '25580474644'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
96 26 654901552 458347153 165510759 938829925 195217130 507375330 505924632 413472221 654752848 711653336 843934470 721570198 773665886 401710037 234904469 980379861 955790468 908963841 767941919 649831102 551860594 482287589 445315312 465411688 121261567 38031091 85608696 831434175 898543690 533481...
output:
20912597347
result:
ok single line: '20912597347'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
97 50 601727246 586947184 629061466 495053188 908476392 789027930 127214423 866336725 518731382 132785533 113489768 827723755 985313205 850125600 651615014 585565934 7844301 974793551 821451342 503266415 191392244 172018292 811053096 980886405 414007158 116164410 749815864 858185057 809840877 654635...
output:
35572528711
result:
ok single line: '35572528711'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
95 53 149550762 262774006 70645562 988470529 951317142 587455395 640797744 881023050 152099375 109591790 42073955 240106850 787394186 32306392 690229700 154829125 612427906 799230609 529294971 846139787 399369072 840851479 258683206 624167919 933584741 989196725 928112368 809131208 742906726 7228213...
output:
38104623964
result:
ok single line: '38104623964'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
95 67 219655106 209971230 684228500 55963835 376681839 957451928 44063570 464399636 244459351 255445846 926539875 699539831 624720901 149661354 268068448 124041530 391618918 196971593 259894666 522352998 72651673 750483217 418558834 288939175 987660441 756241680 290013706 540390088 672554190 1595528...
output:
42726885227
result:
ok single line: '42726885227'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
98 83 144189007 599184430 955720138 430137031 46813950 337012077 284624496 923370172 585878255 277696686 458874123 25220195 65996741 918738892 536999214 420249860 124871436 785740035 524616035 321557657 377122912 363899088 800060966 799482628 704695498 739563311 385588901 543586072 594428502 6483895...
output:
47720376527
result:
ok single line: '47720376527'
Test #7:
score: -5
Wrong Answer
time: 0ms
memory: 3832kb
input:
96 38 37921502 265183642 30462271 269145614 51895518 29824956 44764507 681512686 47724467 815499441 6427327 591731270 46504734 436644698 2223048 132007665 40380520 511674250 43917077 653531209 17511337 975498424 1931641 115779401 16884852 128795730 14731353 429591965 5850509 790146440 15255306 77070...
output:
415960048
result:
wrong answer 1st lines differ - expected: '399264493', found: '415960048'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%