QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#723504#9528. New Energy VehicleSTASISZHYWA 0ms21396kbC++142.1kb2024-11-07 22:38:022024-11-07 22:38:02

Judging History

This is the latest submission verdict.

  • [2024-11-07 22:38:02]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 21396kb
  • [2024-11-07 22:38:02]
  • Submitted

answer

// Problem: A - New Energy Vehicle
// Contest: Virtual Judge - 思维
// URL: https://vjudge.net/contest/670080#problem/A
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

// #pragma GCC optmize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PII pair<int, int>

using namespace std;

const int N = 2e5 + 10, M = 1e6 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;

int n, m, q, ans;
int s[N], dp[N], cy[N], lst[N], nxt[N];
bool vis[N];
PII p[N];

vector<int> e[N];
list<int> v[N];

signed main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T; cin >> T;
	while(T --)
	{
		priority_queue<PII, vector<PII>, greater<> > pq;
		cin >> n >> m; int sum = 0, tag = 0; bool flag = false;
		for(int i = 1; i <= n; i ++) lst[i] = -1, nxt[i] = -1;
		// for(int i = 1; i <= n; i ++) vis[i] = false;
		for(int i = 1; i <= n; i ++) {cin >> s[i]; cy[i] = s[i];}
		for(int i = 1; i <= m; i ++) {cin >> p[i].fi >> p[i].se; v[p[i].se].push_back(p[i].fi);}
		for(int i = 1; i <= n; i ++) v[i].push_back(INF);
		for(int i = 1; i <= n; i ++)
		{
			int now = v[i].front(); v[i].pop_front();
			pq.push({now, i});
		}
		for(int i = 1; i <= m; i ++)
		{
			int dis = p[i].fi - p[i - 1].fi;
			while(!pq.empty() && dis)
			{
				while(pq.top().fi < i) {pq.pop(); continue;}
				int now = pq.top().se, id = pq.top().fi; pq.pop();
				if(!s[now]) continue;
				if(s[now] > dis)
				{
					s[now] -= dis, dis = 0, pq.push({id, now});
					break;
				}
				else dis -= s[now], s[now] = 0;
			}
			// cout << "dis = " << dis << '\n';
			if(dis) 
			{
				sum += p[i].fi - p[i - 1].fi - dis;
				break;
			}
			s[p[i].se] = cy[p[i].se];
			PII x = {INF, p[i].se};
			if(!v[p[i].se].empty()) x.fi = v[p[i].se].front(), v[p[i].se].pop_front();
			if(!pq.empty() && pq.top().se == p[i].se) pq.pop();
			pq.push(x); sum += p[i].fi - p[i - 1].fi;
		}
		for(int i = 1; i <= n; i ++) sum += s[i];
		cout << sum << '\n';
		// if(!flag) cout << p[m].fi + (sum - tag) << '\n';
	}	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 19544kb

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: 0ms
memory: 21396kb

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
9
999999999
2000000000

result:

wrong answer 4th lines differ - expected: '11', found: '9'