QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#708932 | #9528. New Energy Vehicle | Martian148 | WA | 0ms | 3644kb | C++20 | 1.8kb | 2024-11-04 09:47:33 | 2024-11-04 09:47:39 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
constexpr int INF = 2e9;
void solve() {
int n, m; std::cin >> n >> m;
std::vector<int> a(n + 1, 0);
for (int i = 1; i <= n; i++)
std::cin >> a[i];
std::vector<int> x(m + 1, 0), t(m + 1, 0);
std::vector<int> b(n + 1, 0), nxt(m + 1, 0);
for (int i = 1; i <= m; i++)
std::cin >> x[i] >> t[i];
std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, std::greater<std::pair<int, int>>> pq;
std::fill(b.begin(), b.end() , m + 1);
for (int i = m; i >= 1; i--) {
nxt[i] = b[t[i]];
b[t[i]] = i;
}
for (int i = 1; i <= n; i++) {
if (b[i] == m + 1)
pq.push({INF, i});
else
pq.push({x[b[i]], i});
}
std::vector<int> now_a = a;
int ans = 0;
x.push_back(INF);
for (int i = 1; i <= m + 1; i++) {
int len = x[i] - x[i - 1];
while (!pq.empty() && pq.top().first < x[i]) pq.pop();
while (!pq.empty()) {
if (len <= 0) break;
auto [pos, id] = pq.top();
if (now_a[id] < len) {
pq.pop();
len -= now_a[id];
ans += now_a[id];
now_a[id] = 0;
}
else {
now_a[id] -= len;
ans += len;
len = 0;
}
}
if (len > 0) break;
now_a[t[i]] = a[t[i]];
if (nxt[i] != m + 1)
pq.push({nxt[i], t[i]});
else
pq.push({INF, t[i]});
}
std::cout << ans << '\n';
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr); std::cout.tie(nullptr);
int T; 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: 3552kb
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: 3644kb
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:
6 11 4 11 999999999 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '6'