QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#717795 | #9528. New Energy Vehicle | Nyans | RE | 0ms | 5808kb | C++14 | 1.9kb | 2024-11-06 18:58:10 | 2024-11-06 18:58:11 |
Judging History
answer
// test
#include <bits/stdc++.h>
typedef long long s64;
const int N = 100100;
int n, m;
int a[N], b[N];
std::priority_queue< std::pair<int, int> > q;
int pos[N], id[N];
int fir[N];
int lst[N], net[N];
void work() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i ++) b[i] = a[i];
for (int i = 1; i <= n; i ++) fir[i] = lst[i] = net[i] = 0;
for (int i = 1; i <= m; i ++) {
scanf("%d%d", &pos[i], &id[i]);
int u = id[i];
if (!fir[u]) {
fir[u] = i;
} else {
net[lst[u]] = i;
}
lst[u] = i;
net[i] = m + 1;
}
while (q.size()) q.pop();
for (int i = 1; i <= n; i ++)
if (fir[i])
q.push(std::make_pair(-fir[i], i));
else
q.push(std::make_pair(-m - 1, i));
s64 walk = 0;
for (int i = 0; i < m; i ++) {
int delta = pos[i + 1] - pos[i];
while (delta && q.size()) {
std::pair<int, int> now = q.top();
int x = now.second;
if (delta >= b[x]) {
walk += b[x];
delta -= b[x], b[x] = 0;
q.pop();
} else {
walk += delta;
b[x] -= delta, delta = 0;
}
}
if (delta) {
printf("%lld\n", walk);
return;
}
if (q.top().first == -i - 1) q.pop();
// for (int x = 1; x <= n; x ++)
// printf(" %d", b[x]);
// puts("");
b[id[i + 1]] = a[id[i + 1]];
q.push(std::make_pair(-net[i + 1], id[i + 1]));
}
while (q.size()) {
int x = q.top().second; q.pop();
walk += b[x];
}
printf("%lld\n", walk);
}
int main() {
int T;
scanf("%d", &T);
while (T --)
work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5808kb
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
Runtime Error
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