QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#775662 | #8057. Best Carry Player 4 | New_Folder# | WA | 43ms | 7744kb | C++20 | 1.4kb | 2024-11-23 16:25:35 | 2024-11-23 16:25:35 |
Judging History
answer
#pragma GCC optimize(2)
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll m, a[500005], b[500005];
bool fuck[500005];
void solve(){
cin >> m;
ll s1 = 0, s2 = 0;
for(int i = 0; i < m; ++i) {
cin >> a[i];
s1 += a[i];
}
for(int i = 0; i < m; ++i) {
cin >> b[i];
s2 += b[i];
}
if(s1 > s2) {
for(int i = 0; i < m; ++i) {
swap(a[i], b[i]);
}
}
for(int i = 0; i < m; ++i) fuck[i] = a[i] > 0;
int last = -1;
bool ok = 0;
for(int i = 1; i < m; ++i) {
if(b[m - i] > 0) last = m - i;
if(a[i] == 0) continue;
if(last != -1) {
ok = 1;
}
}
if(!ok) {
cout << 0 << '\n';
return;
}
ll res = 0;
for(int i = 0; i < m; ++i) {
int j = m - i - 1;
int tmp = min(a[i], b[j]);
res += tmp;
a[i] -= tmp;
b[j] -= tmp;
}
ok = 0;
bool dmm = 0;
last = m;
int add = 0;
for(int i = 1; i < m; ++i) {
if(b[m - i] > 0) last = m - i;
if((fuck[i] & (last != m))) {
ok = 1;
--b[last];
if(a[i] > 0) {
--a[i];add = 1;
}
break;
}
}
if(!ok) {
cout << res - 1 << '\n';
}
else {
ll sum = 0, ress = 0;
for(int i = 0; i < m; ++i) {
sum += b[m - i - 1];
ll tmp = min(sum, a[i]);
ress += tmp;
sum -= tmp;
}
cout << ress + res + b[m - 1] + add << '\n';
}
}
int main(){
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;cin>>T;while(T--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7744kb
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: -100
Wrong Answer
time: 43ms
memory: 5628kb
input:
100000 5 0 1 1 1 1 0 0 1 0 0 5 0 0 0 0 0 1 1 1 0 0 5 0 0 2 1 1 0 2 1 0 1 5 0 0 0 0 0 1 2 1 0 0 5 0 1 0 1 1 0 0 1 1 1 5 2 0 0 0 1 1 0 0 0 3 5 2 0 0 1 1 0 2 1 1 1 5 0 0 0 0 2 0 0 0 0 1 5 0 0 0 0 0 0 1 1 0 0 5 4 0 0 0 0 0 0 0 1 0 5 0 0 0 0 1 2 1 1 0 0 5 0 2 3 0 0 0 0 0 1 0 5 1 1 1 0 1 1 0 1 0 1 5 0 0 0...
output:
2 0 4 0 2 3 3 2 0 0 1 1 3 0 3 0 0 0 0 0 0 0 4 0 4 1 0 1 4 3 1 4 0 0 2 0 0 1 1 0 0 3 5 4 2 2 2 0 0 2 2 2 0 5 0 1 0 1 0 1 0 4 0 0 2 2 0 3 3 0 1 0 1 0 0 1 0 2 0 4 4 0 2 6 0 2 1 0 0 0 3 2 3 0 1 0 4 3 3 0 2 2 0 1 3 1 1 0 0 0 1 0 3 2 2 0 2 1 1 0 1 0 0 2 4 1 3 3 2 2 2 0 2 0 0 2 3 1 2 1 0 2 2 4 0 1 2 0 1 0 ...
result:
wrong answer 5th numbers differ - expected: '3', found: '2'