QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#333404 | #8057. Best Carry Player 4 | xuqin | WA | 13ms | 5824kb | C++14 | 2.1kb | 2024-02-19 21:27:36 | 2024-02-19 21:27:36 |
Judging History
answer
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<utility>
#include<ctime>
#include<vector>
#include<queue>
#include<iostream>
#include<set>
#include<random>
#include<cassert>
#include<string>
#include<cmath>
#include<bitset>
#include<chrono>
#include<map>
#include<unordered_map>
#define eb emplace_back
using namespace std;
const int maxn=5e5+10, maxm=1.2e4+10, inf=2e9+12;
typedef long long LL;
typedef unsigned long long ULL;
const LL INF=4e18;
typedef pair<int, int> pii;
typedef pair<LL, int> pli;
typedef pair<int, LL> pil;
inline int read() {
int x=0, f=1; char c=getchar();
for(; c<'0'||c>'9'; c=getchar()) if(c=='-') f=0;
for(; c>='0'&&c<='9'; c=getchar()) x=x*10+c-'0';
return f?x:-x;
}
int P=1e9;
inline int add(int x, int y) {x+=y; return x>=P?x-P:x;}
inline int del(int x, int y) {x-=y; return x<0?x+P:x;}
inline int ksm(int x, int y) {
int s=1; for(; y; y>>=1, x=1LL*x*x%P) if(y&1) s=1LL*s*x%P; return s;
}
mt19937 rnd((unsigned)chrono::steady_clock::now().time_since_epoch().count());
int gcd(int x, int y) {return y?gcd(y, x%y):x;}
LL a[maxn], b[maxn];
int main() {
int T=read();
while(T--) {
int m=read();
LL suma=0, sumb=0;
for(int i=0; i<m; ++i) a[i]=read(), suma+=a[i];
for(int i=0; i<m; ++i) b[i]=read(), sumb+=b[i];
if(suma<sumb) a[0]+=sumb-suma; else b[0]+=suma-sumb;
int mxa=0, mxb=0;
for(int i=0; i<m; ++i) if(a[i]>0) mxa=i;
for(int i=0; i<m; ++i) if(b[i]>0) mxb=i;
if(mxa+mxb<m) {printf("0\n"); continue;}
LL c=0; int t=m-1, fl=0, mna=1e9, mnb=1e9;
for(int i=0; i<m; ++i) {
while(t>=m-i-1) {
LL tmp=min(a[i], b[t]);
if(tmp>0) {
if(i+t>=m) fl=1;
mna=min(mna, i);
mnb=min(mnb, t);
}
c+=tmp; a[i]-=tmp; b[t]-=tmp;
if(b[t]==0) --t;
if(a[i]==0) break;
}
}
if(fl) printf("%lld\n", c);
else printf("%lld\n", c-1);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5824kb
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: 13ms
memory: 5824kb
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:
1 0 4 0 3 3 3 2 0 0 1 0 2 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 1 0 0 2 2 2 0 3 0 2 1 1 0 1 0 4 0 0 2 2 0 3 3 0 2 0 1 0 0 1 1 2 0 3 4 0 2 5 0 1 1 0 0 0 2 1 3 0 1 0 4 3 3 0 2 2 0 1 3 1 1 0 0 0 1 0 3 2 2 0 1 0 1 0 1 0 0 2 4 1 2 3 2 2 2 0 1 0 0 2 3 1 3 0 0 2 2 3 0 1 2 0 1 1 ...
result:
wrong answer 1st numbers differ - expected: '2', found: '1'