QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#722567#8057. Best Carry Player 4QingTian#WA 57ms9728kbC++201.3kb2024-11-07 19:33:432024-11-07 19:33:45

Judging History

你现在查看的是最新测评结果

  • [2024-11-07 19:33:45]
  • 评测
  • 测评结果:WA
  • 用时:57ms
  • 内存:9728kb
  • [2024-11-07 19:33:43]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define debug(x) cerr <<#x <<" = " << x << endl
#define fi first
#define se second
using namespace std;
const int N = 5e5 +10;
int T= 1;

int n, a[N], b[N], tem[N], c[N];

void solve(){
	cin >> n;
	int m = n;
	int la = 0, lb = 0;
	for (int i = 0; i < n; i ++) cin >> a[i], la += a[i], c[i] = 0;
	for (int i = 0; i < n; i ++) cin >> b[i], lb += b[i];
	if (lb > la){
		for (int i = 0; i < n; i ++) tem[i] = a[i];
		for (int i = 0; i < n; i ++) a[i] = b[i], b[i] = tem[i];
	}
	int p = 0, s = 0, fl = 0, kid = 0;
    for (int i = n - 1; i >= 0; i --){
    	p = max(p, n - 1 - i);
    	while (b[i] && p < n){
    		if (p + i >= m) fl = 1;
    		int t = min(b[i], a[p]);
    		if (t) kid ++;
    		b[i] -= t, a[p] -= t, s += t;
    		c[i] += t;
    		if (!a[p]) p ++;
    	}
    }
    int cc = 0;
    for (int i = 1; i < n; i ++){
    	int r = m - i;
    	if (c[r]) cc = 1;
    	if (cc && a[i]){
    		fl = 1;
    		a[i] --;
    		break;
    	}
    }
    if (a[n - 1] || b[n - 1]) s += max(a[n - 1], b[n - 1]);
    if (fl) return void(cout << s << endl);
    if (kid > 1) cout << s - 1 << endl;
    else cout << 0 << endl;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> T;
	while(T --) solve();

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 9704kb

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: 57ms
memory: 9728kb

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
1
0
0
1
1
3
0
3
0
0
0
0
0
0
0
3
0
3
1
0
2
3
2
1
4
0
0
2
0
0
1
1
0
0
3
4
3
2
2
1
0
1
2
2
2
0
3
0
2
1
1
0
1
0
4
0
0
2
2
0
3
2
0
2
0
1
0
0
1
1
2
1
3
4
0
2
4
0
2
1
0
0
0
3
2
3
0
2
0
4
3
3
0
1
1
0
1
3
1
1
0
0
0
1
0
3
2
2
0
2
1
1
1
2
0
0
2
3
1
3
3
2
2
2
0
2
0
0
1
3
1
3
1
0
2
2
3
0
1
2
0
1
1
...

result:

wrong answer 8th numbers differ - expected: '2', found: '1'