QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#698134 | #9528. New Energy Vehicle | wuyunzhishi | WA | 0ms | 3632kb | C++20 | 1.3kb | 2024-11-01 17:36:03 | 2024-11-01 17:36:04 |
Judging History
answer
#include <bits/stdc++.h>
using ll = long long;
int inf = 0x3f3f3f3f;
void solve() {
int n, m; std::cin >> n >> m;
std::vector<ll> a(n + 1), x(m + 1, 0), t(m + 1, 0), able(m + 1, 0), prior(n + 1, inf);
for(int i = 1; i <= n; i++) std::cin >> a[i];
for(int i = 1; i <= m; i++) std::cin >> x[i] >> t[i];
auto cmp = [&](int x, int y) {
return prior[x] > prior[y];
};
std::priority_queue<int, std::vector<int>, decltype(cmp)> pq(cmp);
std::vector g(n + 1, std::deque<int>());
for(int i = 1; i <= m; i++) {
g[t[i]].push_back(x[i]);
}
for(int i = 1; i <= n; i++) g[i].push_back(inf);
for(int i = 1; i <= n; i++) prior[i] = g[i].front();
for(int i = 1; i <= n; i++) pq.push(i);
std::vector<ll> b = a;
ll d = 0;
for(int i = 1; i <= m; i++) {
g[t[i]].pop_front();
prior[t[i]] = g[t[i]].front();
while(!pq.empty() && d < x[i]) {
int u = pq.top();
if(b[u] >= x[i] - d) {
b[u] -= x[i] - d;
d = x[i];
if(u == t[i]) pq.pop();
break;
}
else {
d += b[u];
b[u] = 0;
pq.pop();
}
}
b[t[i]] = a[t[i]];
pq.push(t[i]);
}
for(int i = 1; i <= n; i++) d += b[i];
std::cout << d << '\n';
}
int main()
{
//std::ios::sync_with_stdio(0);
//std::cin.tie(0);
//std::cout.tie(0);
int t = 1;
std::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: 3496kb
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: 3632kb
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 11 10 11 1999999998 2000000000
result:
wrong answer 3rd lines differ - expected: '4', found: '10'