QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#686363 | #9528. New Energy Vehicle | ADivT | WA | 0ms | 3556kb | C++14 | 1.8kb | 2024-10-29 11:44:23 | 2024-10-29 11:44:23 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
#define rep(i, o, p) for (int i = o; i <= p; i++)
using namespace std;
typedef long long ll;
const ll INF = 1e17;
void sol() {
int n, m;
cin >> n >> m;
vector<ll> a(n + 5), pos(m + 5), c(m + 5), t(n + 5);
map<ll, ll> mp, list;
vector<ll> tmp(n + 5);
set<ll> s;
rep(i, 1, n) {
cin >> a[i];
t[i] = a[i];
}
rep(i, 1, m) {
cin >> pos[i] >> c[i];
mp[pos[i]] = c[i]; // pos x has y
if (tmp[c[i]])
list[tmp[c[i]]] = pos[i];
else
s.insert(pos[i]);
tmp[c[i]] = pos[i];
}
rep(i, 1, m) {
if (!list[pos[i]]) list[pos[i]] = INF + mp[pos[i]];
}
rep(i, 1, n) {
if (!tmp[i]) s.insert(INF + i);
mp[INF + i] = i;
}
ll ans = 0;
rep(i, 1, m) {
// while (*s.begin() < pos[i]) {
// ll a = *s.begin();
// s.erase(s.begin());
// if (list[a]) s.insert(list[a]);
// }
ll l = pos[i] - pos[i - 1];
ll cnt = 0;
auto it = *s.begin();
while (s.size()) {
if (t[mp[it]] >= l) {
t[mp[it]] -= l;
if (!t[mp[it]]) s.erase(it);
cnt += l;
break;
} else {
l -= t[mp[it]];
cnt += t[mp[it]];
t[mp[it]] = 0;
s.erase(it);
it = *s.begin();
}
}
ans += cnt;
// cout << ans << endl;
// rep(i, 1, n) cout << t[i] << " ";
// cout << endl;
if (ans < pos[i]) break;
t[c[i]] = a[c[i]];
if (list[pos[i]]) s.insert(list[pos[i]]);
if (!s.size()) break;
}
rep(i, 1, n) ans += t[i];
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) sol();
return 0;
}
/*
2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1
*/
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3556kb
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1
output:
12 8
result:
wrong answer 2nd lines differ - expected: '9', found: '8'