QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#709891 | #9528. New Energy Vehicle | ghosh__# | WA | 3ms | 72108kb | C++23 | 1.6kb | 2024-11-04 17:19:20 | 2024-11-04 17:19:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define int long long
const int maxn = 1e5 + 5;
int n, m, a[maxn], x[maxn], t[maxn], b[maxn];
queue<int> q[maxn];
void Solve() {
cin >> n >> m;
for (int i = 1; i <= n; i++) while (q[i].size()) q[i].pop();
for (int i = 1; i <= n; i++) {
cin >> a[i];
b[i] = a[i];
}
for (int i = 1; i <= m; i++) {
cin >> x[i] >> t[i];
q[t[i]].push(x[i]);
}
int cur = 0;
set<pair<int,int>> s;
for (int i = 1; i <= n; i++) {
if (q[i].size()) {
s.insert({q[i].front(), i});
q[i].pop();
}
}
int now = 0;
while (now < m) {
int res = x[now + 1] - cur;
while (res) {
if (s.empty()) break;
int id = s.begin() -> second;
int val = min(res, a[id]);
res -= val;
a[id] -= val;
cur += val;
if (!a[id]) s.erase(s.begin());
}
if (res) break;
now++;
a[t[now]] = b[t[now]];
int col = t[now];
if (s.find({x[now], t[now]}) != s.end()) s.erase({x[now], t[now]});
if (q[col].size()) {
s.insert({q[col].front(), col});
q[col].pop();
}
}
for (int i = 1; i <= n; i++) cur += a[i];
cout << cur << endl;
}
signed main() {
//freopen("in", "r", stdin);
//freopen("out", "w", stdout);
int T;
cin >> T;
while (T--){
Solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 72108kb
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1
output:
9 9
result:
wrong answer 1st lines differ - expected: '12', found: '9'