QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#722593#9528. New Energy VehicleyykWA 0ms3616kbC++141.3kb2024-11-07 19:37:512024-11-07 19:37:54

Judging History

This is the latest submission verdict.

  • [2024-11-07 19:37:54]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3616kb
  • [2024-11-07 19:37:51]
  • Submitted

answer

#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm>
#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 main() {
	int T;
	cin>>T;
	while(T--){
		cin>>n>>m;
		queue<int> h[n+10];
		priority_queue<PII,vector<PII>,greater<PII>> pq;
		for(int i=1;i<=n;++i){
			cin>>a[i];
		}
		for(int i=1;i<=m;++i){
			cin>>b[i].x>>b[i].y;
			h[b[i].y].push(i);
		}
		for(int i=1;i<=n;++i){
			if(h[i].size()){
				int t=h[i].front();
				h[i].pop();
				pq.push({t,a[i]});
			}
			else{
				pq.push({1e9,a[i]});
			}
		}
		LL now=0;
		for(int i=1;i<=m;++i){
			while(pq.size()&&pq.top().x<i) pq.pop();
			while(pq.size()&&now<b[i].x){
				PII t=pq.top();
				pq.pop();
				int tmp=min(b[i].x-now,(LL)t.y);
				now+=tmp;
				t.y-=tmp;
				if(t.y){
					pq.push(t);
				}
			}
			if(now==b[i].x){
				if(h[b[i].y].size()){
					int t=h[b[i].y].front();
					h[b[i].y].pop();
					pq.push({t,a[b[i].y]});
				}
				else{
					pq.push({1e9,a[b[i].y]});
				}
			}
		}
		while(pq.size()&&pq.top().x<=n) pq.pop();
		while(pq.size()){
			PII t=pq.top();
			cout<<t.y<<endl;
			pq.pop();
			now+=t.y;
		}
		cout<<now<<endl;
	}
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3616kb

input:

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

output:

1
3
12
2
5
9

result:

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