QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#706857#9528. New Energy Vehicleleafmaple#WA 1ms3780kbC++201.5kb2024-11-03 13:43:142024-11-03 13:43:16

Judging History

This is the latest submission verdict.

  • [2024-11-03 13:43:16]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3780kb
  • [2024-11-03 13:43:14]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> nxa[100000+10];
int nx[100000+10];
void solve()
{
	int n,m;
	cin>>n>>m;
	vector<int> a(n+1);
	
	for(int i=1;i<=n;i++)
		cin>>a[i];
	vector<pair<int,int> > now(m+1);
	for(int i=1;i<=n;i++)
	{
		nxa[i].clear();
		nx[i] = 0;
		
	}
	for(int i=1;i<=m;i++)
	{	cin>>now[i].first>>now[i].second ;
		nxa[now[i].second].push_back(i);
	}
	for(int i=1;i<=n;i++)
	{
		nxa[i].push_back(m+1);
	}
	priority_queue<pair<int,int> ,vector<pair<int,int> > ,greater<pair<int,int> > > q;
	for(int i=1;i<=n;i++)
	{
		q.push({nxa[i][0],a[i]});
	}
	int nowl = 0 ;
	for(int i=1;i<=m;i++)
	{	
		while(!q.empty()&&now[i].first != nowl )
		{
			auto[u,w] = q.top();
			q.pop();
			int sub = now[i].first - nowl;
			if(sub < w)
			{
				nowl = now[i].first;
				w -= sub;
				if(now[i].second == u)
				{
					nx[ now[i].second ] ++;
					q.push({nxa[now[i].second][nx[now[i].second]],a[now[i].second]});
				}
				else 
				{
					q.push({u,w});
					nx[ now[i].second ] ++;
					q.push({nxa[now[i].second][nx[now[i].second]],a[now[i].second]});
				}
			}
			else 
			{
				nowl = nowl + w ;
			}
			
		}
		if(now[i].first != nowl)
		{
			break;
		}
	}
	while(!q.empty())
	{
		auto [u,w] = q.top();
		q.pop();
		nowl += w;
	}
	cout<<nowl<<endl;
	
	
}  
signed main (){
	std::ios::sync_with_stdio(false);  
	cin.tie(NULL); 
	cout.tie(NULL);
	int t;
	cin>>t;
	while(t--)
		solve();
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3544kb

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:

6
11
4
11
999999999
1000000000

result:

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