QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#673366 | #8057. Best Carry Player 4 | lonelywolf# | TL | 101ms | 3576kb | C++20 | 1.2kb | 2024-10-24 21:56:47 | 2024-10-24 21:56:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int m;
cin >> m;
int sa = 0, sb = 0;
vector<int> a(m), b(m);
for (int i = 0; i < m; i++) {
cin >> a[i];
sa += a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
sb += b[i];
}
if (sa > sb) {
b[0] += sa - sb;
} else {
a[0] += sb - sa;
}
reverse(b.begin(), b.end());
int mx = 0;
auto work = [&]() {
int ans = 0;
int s = 0;
for (int i = 0; i < m; i++) {
s += b[i];
if (s >= a[i]) {
s -= a[i];
ans += a[i];
} else {
ans += s;
s = 0;
}
}
// for (int i = 0; i < m; i++) {
// cout << a[i] << " \n"[i + 1 == m];
// }
// for (int i = 0; i < m; i++) {
// cout << b[i] << " \n"[i + 1 == m];
// }
// cout << ans << "\n";
return ans;
};
for (int i = 0; i < m; i++) {
for (int j = i + 1; j < m; j++) {
if (b[i] > 0 && a[j] > 0) {
a[j]--, b[i]--;
mx = max(work() + 1, mx);
a[j]++, b[i]++;
}
}
}
cout << mx << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3516kb
input:
5 2 1 2 3 4 3 1 0 1 0 1 0 4 1 0 0 1 1 1 1 1 5 123456 114514 1919810 233333 234567 20050815 998244353 0 0 0 10 5 3 5 3 2 4 2 4 1 5 9 9 8 2 4 4 3 5 3 0
output:
5 1 2 467900 29
result:
ok 5 number(s): "5 1 2 467900 29"
Test #2:
score: 0
Accepted
time: 47ms
memory: 3536kb
input:
100000 5 0 1 1 1 1 0 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3 1 3 1 3 4 2 1 1 2 3 0 0 1 2 0 0 1 1 1 1 2 1 2 2 0 2 2 1 1 3 0 0 1 2 0 1 3 0 0 1 1 0 0 1 0 3 1 2 0 0 5 1 1 1 3 1 4 1 0 0 0 0 0 1 3 1 2 1 0 0 0 0 0 1 1 0 4 0 1 1 3 0 1 0 0 2 3 0 1 2 1 1 1 0 3 0 0 3 2 1 1 0 1 0 1 ...
result:
ok 1000 numbers
Test #4:
score: 0
Accepted
time: 75ms
memory: 3480kb
input:
100000 5 119777838 337555280 806504015 458289944 321614229 979242871 431783189 423329635 193632121 7339369 5 189264782 667669243 753322761 861814678 224007583 977519325 104432095 940220826 712094722 903574615 5 977791540 278658984 601762324 633391706 36807634 689562032 997406456 118939957 891425821 ...
output:
1377698543 2884329841 1699584169 2132012702 2531472710 2754014935 2585135038 2577893498 2034726862 2303377730 1476887044 2618960687 1626312268 1068946376 600795101 927483202 2151016849 2256729729 2291627593 1751199962 2412405837 1884010446 2553701265 2014856631 848686688 1069641213 2412585811 167144...
result:
ok 100000 numbers
Test #5:
score: 0
Accepted
time: 88ms
memory: 3576kb
input:
50000 10 18209490 798013131 762297136 184230300 323229686 771738936 850827138 201740028 818693101 945688434 101715068 966337103 309026840 698679951 666034197 810411289 841033024 740762082 484989962 19640395 10 608177485 700383507 317699894 982085408 908794603 92931066 880099629 965892642 576147264 9...
output:
5341540062 3811346608 3280168940 4222050470 4327730826 4389011469 5146997799 3799138189 4028437054 3650616128 4267213780 5220650313 3272450503 3560399774 5130261345 4384881302 4681302604 5415587476 2376088103 3344427945 3701410392 3434767065 4969556102 4474318648 4751503347 3701971157 5053000969 397...
result:
ok 50000 numbers
Test #6:
score: -100
Time Limit Exceeded
input:
5000 100 405163017 116989072 685766112 551211950 862199350 861827829 564364529 922314891 241721254 160976656 891732149 553649064 445152950 859742462 235262967 648909226 943054063 484936253 414150625 995061073 662853643 367723189 348457562 591856009 309322986 450413840 159926452 24214846 79239852 397...
output:
44348367445 47318596151 43893435579 49579921753 48669603728 45875221434 49002488594 53587378598 52208712766 49588253701 50196256163 49596309746 48141429048 49878478140 49036091100 46395088830 42672527744 41761915575 47439675311 47743457344 44672635972 50006245688 49397345810 46906644735 49589049416 ...