QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#686337 | #9528. New Energy Vehicle | ADivT | WA | 0ms | 3608kb | C++14 | 1.8kb | 2024-10-29 11:28:23 | 2024-10-29 11:28:24 |
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, 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();
bool flag = 1;
while (1) {
// cout << 73;
if (t[mp[it]] >= l) {
// cout << mp[it] << endl;
// cout << "73";
t[mp[it]] -= l;
if (!t[mp[it]]) s.erase(it);
cnt += l;
break;
} else {
// cout << 2;
l -= t[mp[it]];
cnt += t[mp[it]];
t[mp[it]] = 0;
s.erase(it);
// if (list[it]) s.insert(list[it]);
if (s.size())
it = *s.begin();
else {
flag = 0;
break;
}
}
}
ans += cnt;
if (flag == 0) break;
t[c[i]] = a[c[i]];
s.insert(list[pos[i]]);
}
// cout << ans << t[1] << t[2] << endl;
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
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 8 4 8 999999999 2000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '8'