QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#683402#9528. New Energy VehicleHHAZ#WA 0ms3604kbC++201.8kb2024-10-27 20:48:572024-10-27 20:48:58

Judging History

This is the latest submission verdict.

  • [2024-10-27 20:48:58]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3604kb
  • [2024-10-27 20:48:57]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
#define endl '\n'
#define sz(x) (int)(x).size()
#define all(t) (t).begin(), (t).end()
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for(ll i = (a); i >= (b); --i)
#define debug(x) cout<<#x<<": "<<x<<endl
const int N=2e5+10,M=1e6+10;


pair<int,int> b[N];
int a[N];
int c[N];
void solve() 
{
	ll n,m;
	cin>>n>>m;
	stack<int> st[n+1];
	
	map<int,int>ma;
	rep(i,1,n)
	{
		cin>>a[i];
		c[i]=a[i];
	}
	rep(i,1,m)
	{
		cin>>b[i].first>>b[i].second;
	}
	per(i,m,1)
	st[b[i].second].push(b[i].first);
	int op=1;
	rep(i,1,n)
	{	
		if(st[i].size())
		{
			ma[st[i].top()]=i;
			st[i].pop();
		}
		else
		ma[1e9+(op++)]=i;
	}	
	int p=1;
	int now=0;
	while(ma.size()&&p<=m)
	{
		auto [x,y]=*ma.begin();
		if(x<now)
		{
			ma.erase(x);
			continue;
		}
		int su=min(b[p].first-now,c[y]);

		c[y]-=su;
		now+=su;
		if(now==b[p].first)
		{
			c[y]=a[y];

			if(st[b[p].second].size())
			{
				ma[st[b[p].second].top()]=b[p].second;
				st[b[p].second].pop();
			}

			p++;
		}
		if(c[y]==0)
		{
			ma.erase(x);
		}
	}
	
	rep(i,1,n)
	{
		now+=c[i];
		c[i]=0;
	}
	
	cout<<now<<endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
	 cin >> T;
	//	cout.flush();
	//		ofstream outfile("C:\\Users\\86187\\OneDrive\\桌面\\1.txt");
	//		outfile << "a[1]=0;a[2]=1;";
	//		ll l = 1e7 + 1;
	//		rep(i, 3, 1e9) {
	//			printf("%lld\n", i);
	//			ll x = (i - 1) * ((a[i - 1] + a[i - 2]) % mod);
	//			x %= mod;
	//			if(i == l) {
	//				outfile << "a[" << i << "]=" << x << ";";
	//			}
	//			if(i == l + 1) {
	//				outfile << "a[" << i << "]=" << x << ";";
	//				l += 1e7;
	//			}
	//		}
	while(T--) {
		solve();
	}
	return 0;
}

详细

Test #1:

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

input:

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

output:

11
9

result:

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