QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#718583 | #9528. New Energy Vehicle | retired_midlights | WA | 0ms | 3604kb | C++14 | 1.6kb | 2024-11-06 20:54:07 | 2024-11-06 20:54:07 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (int)a; i <= (int)b; i ++)
#define per(i, a, b) for(int i = (int)a; i >= (int)b; i --)
#define ll long long
using namespace std;
const int maxn = 100010;
int n, m, a[maxn], b[maxn], t[maxn], nxt[maxn];
ll x[maxn];
void solve() {
cin >> n >> m;
rep(i, 1, n) cin >> a[i], b[i] = a[i];
priority_queue < pair < int, int > > pq;
map < int, int > mp;
rep(i, 1, m) {
cin >> x[i] >> t[i];
pq.push(make_pair(-i, t[i]));
}
per(i, m, 1) {
if(mp.find(x[i]) != mp.end()) nxt[i] = mp[x[i]], mp[x[i]] = i;
else mp[x[i]] = i, nxt[i] = m + 1;
}
rep(i, 1, n) pq.push(make_pair(-(m + 1), i));
ll cur = 0, num = 1;
x[m + 1] = 1e18;
while(!pq.empty()) {
if(pq.top().first > -num) pq.pop();
auto u = pq.top();
while(cur + b[u.second] < x[num]) {
cur += b[u.second];
b[u.second] = 0;
pq.pop();
if(pq.empty()) {
cout << cur << '\n';
return;
}
u = pq.top();
}
b[u.second] -= x[num] - cur;
cur = x[num];
b[t[num]] = a[t[num]];
// rep(i, 1, n) cerr << b[i] << " \n"[i == n];
if(nxt[num] < -u.first) {
// cerr << "add" << '\n';
pq.push(make_pair(-nxt[num], t[num]));
}
num ++;
}
}
int main() {
#ifdef LOCAL
freopen("data.in", "r", stdin);
#endif
ios :: sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int T = 1;
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: 3580kb
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: 3604kb
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'