QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#723227#9528. New Energy VehicleSTASISZHYTL 0ms14148kbC++141.8kb2024-11-07 21:30:522024-11-07 21:30:52

Judging History

This is the latest submission verdict.

  • [2024-11-07 21:30:52]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 14148kb
  • [2024-11-07 21:30:52]
  • 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)

#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];
bool vis[N];
PII p[N];

vector<int> e[N];

signed main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T; cin >> T;
	while(T --)
	{
		vector<PII> pq;
		cin >> n >> m; int sum = 0, tag = 0; bool flag = false;
		// 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; pq.push_back({p[i]});}
		for(int i = 1; i <= n; i ++) pq.push_back({INF, i});
		for(int i = 1; i <= m; i ++)
		{
			int dis = p[i].fi - p[i - 1].fi;
			for(auto j : pq)
			{
				if(j.fi < p[i].fi || !s[j.se]) continue;
				// cout << "dis = " << dis << " now = " << now << " left = " << s[now] << '\n';
				if(s[j.se] > dis) 
				{
					s[j.se] -= dis, dis = 0;
					break;
				}
				else dis -= s[j.se], s[j.se] = 0; 		
			}
			// cout << "dis = " << dis << '\n';
			if(dis) 
			{
				for(int j = 1; j <= n; j ++) 
				{
					if(s[j] > dis) s[j] -= dis, dis = 0;
					else dis -= s[j], s[j] = 0; 		
				}
				if(dis) 
				{
					cout << p[i].fi - dis << '\n'; 
					flag = true; 
					break;
				}
			}
			s[p[i].se] = cy[p[i].se]; pq.push_back({INF, p[i].se});
		}
		if(flag) continue;
		for(int i = 1; i <= n; i ++) sum += s[i];
		cout << p[m].fi + 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: 13092kb

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: 0
Accepted
time: 0ms
memory: 14148kb

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

result:

ok 6 lines

Test #3:

score: -100
Time Limit Exceeded

input:

10
230 8042
599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...

output:


result: