QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#331656 | #8057. Best Carry Player 4 | ucup-team197# | WA | 45ms | 5728kb | C++14 | 1.1kb | 2024-02-18 16:30:39 | 2024-02-18 16:30:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef __int128 ll;
int m;
ll a[500005],b[500005];
void solve(){
cin >> m;
for(int i=0; i<m ;i++){
long long x;cin >> x;a[i]=x;
}
for(int i=0; i<m ;i++){
long long x;cin >> x;b[i]=x;
}
{
ll ta=0,tb=0;
for(int i=0; i<m ;i++){
ta+=a[i];tb+=b[i];
}
ll t=max(ta,tb);
a[0]+=t-ta;
b[0]+=t-tb;
}
ll sa=0,sb=0;
ll res=0;
for(int i=0; i<m ;i++){
sa+=a[i];
sb+=b[m-i-1];
ll cur=min(sa,sb);
res+=cur;
sa-=cur;sb-=cur;
sa=0;
}
ll suma=0,sumb=0;
{
ll frog=res;
for(int i=m-1; i>=0 ;i--){
ll cur=min(a[i],frog);
frog-=cur;
a[i]=cur;
suma+=a[i]*i;
}
}
{
ll frog=res;
for(int i=m-1; i>=0 ;i--){
ll cur=min(b[i],frog);
frog-=cur;
b[i]=cur;
sumb+=b[i]*i;
}
}
//cout << a[0] << ' ' << a[1] << ' ' << b[0] << ' ' << b[1] << ' ' << res << endl;
//cout << res << ' ' << suma << ' ' << sumb << endl;
long long ress=res;
if(res==0 || suma+sumb>res*(m-1)) cout << ress << '\n';
else cout << ress-1 << '\n';
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
int t;cin >> t;while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5728kb
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: 45ms
memory: 5636kb
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 3 3 3 2 0 0 1 1 3 0 3 0 0 0 0 0 0 0 4 0 4 1 0 2 3 3 1 5 0 0 2 0 0 1 1 0 0 3 5 3 2 2 2 0 1 2 2 2 0 3 0 2 1 1 0 1 0 4 1 1 2 2 0 3 3 0 2 0 1 0 0 1 1 2 0 3 4 0 2 5 0 2 1 0 0 0 3 2 3 0 2 0 4 3 3 0 2 2 1 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 3 1 0 2 2 3 0 1 2 1 1 1 ...
result:
wrong answer 63rd numbers differ - expected: '0', found: '1'