QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#684411#9528. New Energy VehicleihavebigdickWA 0ms3584kbC++141.4kb2024-10-28 13:13:032024-10-28 13:13:04

Judging History

This is the latest submission verdict.

  • [2024-10-28 13:13:04]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3584kb
  • [2024-10-28 13:13:03]
  • Submitted

answer

#include <bits/stdc++.h>

#define x first
#define y second
#define int long long

using PII = std::pair<int, int>;

const int N = 1e5+10, INF = 1e9+10;

void solve()
{
	int n, m; std::cin >> n >> m;
	std::vector<int> a(n+1), enr(n+1);
	std::vector<std::vector<int>> chr(n+1);
	std::vector<int> pos(m+1);
	std::vector<int> idx(m+1);
	std::vector<int> b(m+1);

	for(int i = 1; i <= n; i ++ )
	{
		std::cin >> a[i];
		enr[i] = a[i];
	}

	for(int i = 1; i <= m; i ++ )
	{
		std::cin >> pos[i] >> b[i];
		chr[b[i]].emplace_back(pos[i]);
	}

	std::priority_queue<PII, std::vector<PII>, std::greater<PII> > hp;
	for(int i = 1; i <= n; i ++ )
	{
		chr[i].emplace_back(INF);
		hp.emplace(chr[i][0], i);
	}

	int ans = 0;
	for(int i = 1; i <= m; i ++ )
	{
		int d = pos[i]-pos[i-1];
		while(hp.size())
		{
			auto [x, t] = hp.top();
			int cost = std::min(d, enr[t]);
			enr[t] -= cost;
			d -= cost;
			ans += cost;
			if(!enr[t]) hp.pop();
			if(!d) break;
		}

		if(!d)
		{
			int t = b[i];
			if(hp.size() && hp.top().y == t)
				hp.pop();
			enr[t] = a[t];
			hp.emplace(enr[t], t);
		}

		// for(int x: enr)
		// 	std::cout << x << ' ';
		// std::cout << '\n';
	}

	for(int& x: enr)
		ans += x;

	std::cout << ans << '\n';
}

signed main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int t; std::cin >> t;
	while(t -- )
	{
		solve();
	}

	return 0;
}

详细

Test #1:

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

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

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

result:

wrong answer 2nd lines differ - expected: '11', found: '9'