QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#721982#9528. New Energy VehicleyykWA 1ms4116kbC++141.0kb2024-11-07 17:22:042024-11-07 17:22:05

Judging History

This is the latest submission verdict.

  • [2024-11-07 17:22:05]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 4116kb
  • [2024-11-07 17:22:04]
  • Submitted

answer

#include <cstring>
#include <iostream>
#define x first
#define y second
using namespace std;

typedef long long LL;
typedef pair<int,int> PII; 
const int N=100010;
int n,m;
int a[N],c[N];
PII b[N];
int st[N];

int main() {
	int T;
	cin>>T;
	while(T--){
		cin>>n>>m;
		memset(st,0,sizeof(st));
		LL sum=0,now=0,rom=0;
		for(int i=1;i<=n;++i){
			cin>>a[i];
			c[i]=a[i];
		}
		for(int i=1;i<=m;++i){
			cin>>b[i].x>>b[i].y;
			st[b[i].y]++;
		}
		for(int i=1;i<=n;++i){
			if(st[i]) ;
			else rom+=a[i];
		}
		for(int i=1,j=1;i<=m;++i){
			while(j<=m&&now<b[i].x){
				int t=min(b[i].x-now,(LL)c[b[j].y]);
				c[b[j].y]-=t;
				now+=t;
				if(--st[b[j].y]==0){
					rom+=c[b[j].y];
				}
				++j;
			}
			if(now<b[i].x){
				int t=b[i].x-now;
				if(rom>=t){
					rom-=t;
					now+=t;
				}
				else{
					now+=rom;
					break;
				}
			}
			if(st[b[i].y]==0){
				int t=a[b[i].y]-c[b[i].y];
				c[b[i].y]=a[b[i].y];
				rom+=t;
			}
		}
		now+=rom;
		cout<<now<<endl;
	}
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 1ms
memory: 4084kb

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:

8
11
4
11
999999999
2000000000

result:

wrong answer 1st lines differ - expected: '9', found: '8'