QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#684782#9528. New Energy VehicleweekWA 93ms22164kbC++141.5kb2024-10-28 15:50:112024-10-28 15:50:12

Judging History

This is the latest submission verdict.

  • [2024-10-28 15:50:12]
  • Judged
  • Verdict: WA
  • Time: 93ms
  • Memory: 22164kb
  • [2024-10-28 15:50:11]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int INF = 1e18;
const int N = 1e6 + 10;
const int M = 5020;
const int mod = 998244353;
typedef pair<int,int> PII;
typedef pair<int,PII> pii;
int n,m;
int a[N];
int d[N],b[N],pre[N],num[N];
int x,y;

void solve(){
	cin >> n >> m;
	map<int,int> mm;
	x = 0,y = 0;
	for(int i=1; i<=n; i++) cin >> a[i];
	for(int i=1; i<=m; i++){
		cin >> d[i] >> b[i];
		pre[i] = mm[b[i]];
		mm[b[i]] = i; 
	}
	for(int i=1; i<=n; i++){
		if(mm[i] > 0) y += a[i];
		else x += a[i];
	}
	int sum = y;
	int now = 0;
	vector<PII> v;
	for(int i=1; i<=m; i++){
		int len = 0;
		int xx = d[i] - d[i - 1];
		int dy = 0;
		if(len != xx){
			len = min(y,xx);
			y -= len;
			dy = len;
		}
		if(len != xx){
			int kk = min(xx - len, x);
			x -= kk;
			len += kk;
		}
		now += len;
		int kk = 0;
		int yy = a[b[i]];
		if(len != xx) break;
		else{
			if(dy >= a[b[i]]){
				y += a[b[i]];
				v.push_back({i,dy - a[b[i]]});
			}else{
				yy = a[b[i]] - dy;
				while(v.size() && v.back().first > pre[i] && yy > 0){
					if(v.back().second >= dy) v.back().second -= yy,kk+=yy,yy=0;
					else kk+=yy - v.back().second,yy -= v.back().second,v.pop_back();
				}	
				y += kk + dy;
			}
			if(mm[b[i]] == i) x += a[b[i]],y -= a[b[i]],sum -= a[b[i]]; 
		}
		//cout << y << ' ' << x << ' ' << kk << endl;
	}
	now += x + y;
	cout << now << endl;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T = 1;
	cin >> T;
	while(T--){
		solve();
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 11744kb

input:

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

output:

12
9

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 11840kb

input:

6
3 2
2 2 2
6 1
7 1
2 2
3 3
2 1
6 2
2 3
2 2
5 1
7 2
9 1
2 2
3 3
2 1
6 2
1 1
999999999
1000000000 1
1 1
1000000000
1000000000 1

output:

9
11
4
11
999999999
2000000000

result:

ok 6 lines

Test #3:

score: -100
Wrong Answer
time: 93ms
memory: 22164kb

input:

10
230 8042
599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...

output:

4750236
3167000
3493547
3837463
3505720
3883149
1317947
5115951
1416282
1387306

result:

wrong answer 1st lines differ - expected: '1543020', found: '4750236'