QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#688248#9528. New Energy Vehicledaniel14311531WA 1ms7688kbC++141.8kb2024-10-30 01:30:092024-10-30 01:30:12

Judging History

This is the latest submission verdict.

  • [2024-10-30 01:30:12]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7688kb
  • [2024-10-30 01:30:09]
  • Submitted

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'