QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#775539 | #8057. Best Carry Player 4 | New_Folder# | TL | 0ms | 11452kb | C++20 | 1.5kb | 2024-11-23 16:10:35 | 2024-11-23 16:10:36 |
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];
fuck[i] = a[i] > 0;
}
for(int i = 0; i < m; ++i) {
cin >> b[i];
s2 += b[i];
}
if(s1 > s2) {
swap(a, b);
}
int minn = m, last = -1, aa, bb;
for(int i = 1; i < m; ++i) {
if(b[m - i] > 0) last = m - i;
if(a[i] == 0) continue;
if(last != -1) {
if(minn > i + last - m || (minn == i + last - 1 && last != m - 1)) {
minn = i + last - m;
aa = i;
bb = last;
}
}
}
if(minn == m) {
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;
}
ll sum = 0, ress = 0;
int ok = 0;
bool dmm = 0;
for(int i = 1; i < m; ++i) {
sum += b[m - i];
ll tmp = min(sum, a[i]);
ok = ok | (fuck[i] & (sum > 0));
if((fuck[i] & (sum > 0)) && sum > b[m - 1]) {
dmm = 1;
}
}
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] - 1 + dmm << '\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: 0ms
memory: 11452kb
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
Time Limit Exceeded
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 5 0 4 3 3 2 0 0 1 0 3 0 3 0 0 0 0 0 0 0 4 0 4 1 0 2 4 3 1 5 0 0 2 0 0 1 1 0 0 3 5 4 2 2 2 0 0 2 2 2 0 5 0 2 0 1 0 1 0 4 0 0 2 2 0 3 3 0 2 0 1 0 0 2 1 3 0 4 4 0 2 7 0 2 1 0 0 0 3 2 3 0 2 0 4 3 3 0 3 2 0 1 3 -1 1 0 0 0 1 0 3 2 2 0 2 1 1 0 2 0 0 2 4 1 3 3 2 2 2 0 2 0 0 2 3 1 3 0 0 2 2 4 0 1 0 0 1 0...