QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#801010#9528. New Energy Vehiclelwj1239WA 2ms6232kbC++111.7kb2024-12-06 17:39:102024-12-06 17:39:17

Judging History

This is the latest submission verdict.

  • [2024-12-06 17:39:17]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 6232kb
  • [2024-12-06 17:39:10]
  • Submitted

answer

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define pb push_back
#define pii pair<int,int>
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
typedef long long ll;
using namespace std;
const int N = 100005;
vector<int> a(N);
vector<int> r(N);
vector<int> x(N);//存储第i个充电站的距离
vector<int> t(N);//存储第i个充电站给谁充电
void solve() {
	int n, m;
	cin >> n >> m;
	
	priority_queue<pii, vector<pii>, greater<pii>> s;// 按照pair的第一个键值升序排列的最小堆
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		r[i] = a[i];
	}
	for (int i = 1; i <= m; i++) {
		cin >> x[i] >> t[i];
		s.push({ x[i], t[i] });
	}
	for (int i = 1; i <= n; i++) {
		s.push({INF, i}); //给所有电瓶都设置一个极大位置的充电站
	}
	
	int ans = 0;
	for (int i = 1; i <= m; i++) {
		int len = x[i] - x[i - 1]; //当前充电站与上一站的距离
		while (len > 0) { //按照优先队列的顺序用电
			if (s.empty())break;
			auto top = s.top();
			s.pop();
			if (a[top.second] == 0)continue;
			if (a[top.second] <= len) {
				len -= a[top.second];
				a[top.second] = 0;
			}
			else {
				a[top.second] -= len;
				len = 0;
				break;
			}
		}
		if (len > 0) {//如果电量不足以到达充电站
			ans += (x[i] - x[i - 1] - len);
			break;
		}
		else { //给电瓶充电
			a[t[i]] = r[t[i]];
			ans += x[i] - x[i - 1];
			s.push({x[i] + 1, t[i]});
		}
	}
	for (int i = 1; i <= n; i++) {
		ans += a[i]; //如果有剩余电量,增加到ans中
	}
	cout << ans << endl;

}

signed main() {
	cin.tie(0)->ios::sync_with_stdio(0);
	int T = 1;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 6232kb

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'