QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#688248 | #9528. New Energy Vehicle | daniel14311531 | WA | 1ms | 7688kb | C++14 | 1.8kb | 2024-10-30 01:30:09 | 2024-10-30 01:30:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200010;
int n, m;
int a[N], b[N], c[N];
int nxt[N];
int pos[N], id[N];
bool vis[N];
set<pair<int, int> > st;
ll rem;
void solve() {
cin >> n >> m; rem = 0;
for(int i = 1; i <= n; i++) {
cin >> a[i], b[i] = 0, c[i] = 0;
rem += a[i];
}
for(int i = 1; i <= m; i++) {
cin >> pos[i] >> id[i];
vis[i] = 0;
}
for(int i = m; i; i--) {
nxt[i] = c[id[i]];
if(nxt[i]) vis[nxt[i]] = 1;
c[id[i]] = i;
}
st.clear();
for(int i = 1; i <= m; i++) {
if(!vis[i]) {
st.insert({pos[i], id[i]});
rem -= a[id[i]], b[id[i]] = a[id[i]];
}
}
ll cur = 0;
for(int i = 1; i <= m; i++) {
for(; cur < pos[i];) {
if(st.empty()) {
if(cur + rem >= pos[i]) {
rem -= pos[i] - cur, cur = pos[i];
}
break;
}
else {
auto it = st.begin();
if(b[it->second] + cur >= pos[i]) {
b[it->second] -= pos[i] - cur, cur = pos[i];
}
else {
cur += b[it->second], b[it->second] = 0;
st.erase(st.begin());
}
}
}
if(cur < pos[i]) break;
b[id[i]] = a[id[i]];
if(st.find({pos[i], id[i]}) != st.end()) st.erase(st.find({pos[i], id[i]}));
if(nxt[i]) st.insert({pos[nxt[i]], id[nxt[i]]});
}
cur += rem;
for(int i = 1; i <= n; i++) cur += b[i];
cout << cur << "\n";
}
int main() {
ios::sync_with_stdio(0); cin.tie(nullptr);
int T; cin >> T;
for(; T; --T) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5652kb
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: 7688kb
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'