QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#689426#9528. New Energy Vehicleyingling#WA 0ms3620kbC++202.3kb2024-10-30 16:58:402024-10-30 16:58:42

Judging History

This is the latest submission verdict.

  • [2024-10-30 16:58:42]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3620kb
  • [2024-10-30 16:58:40]
  • Submitted

answer

#include <bits/stdc++.h>
#define endl "\n"
#define int long long
using namespace std;

typedef pair<int, int> PII;

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 7);
    vector<int> cnt(n + 7);
    vector<PII> pd;
    vector<vector<int>> pos(n + 7);
    vector<int> ind(n + 7);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    auto b = a;
    set<PII> st;
    for (int i = 1; i <= m; i++) {
        int x, t;
        cin >> x >> t;
        st.insert({x, t});
        pd.push_back({x, t});
        pos[t].push_back(x);
        cnt[t] ++;
    }
    int now = 0, idx = 0, sum = 0;
    for (int i = 1; i <= n ; i ++) {
        if (!cnt[i])
            sum += a[i];
    }
    while (idx < m) {
        vector<PII> era;
        while (1) {
            for (auto [x, y] : st) {
                if (now + a[y] <= pd[idx].first)
                    now += a[y], a[y] = 0, era.push_back({x, y});
                else {
                    a[y] -= pd[idx].first - now;
                    now = pd[idx].first;
                    break;
                }
            } 
            if (now >= pd[idx].first)
                break;
            if (now + sum <= pd[idx].first) {
                now += sum;
                cout << now << endl;
                return;
            }
            else {
                sum -= pd[idx].first - now;
                now = pd[idx].first;
                break;
            }
        }
        
        a[pd[idx].second] = b[pd[idx].second];
        cnt[pd[idx].second] --;
        if (!cnt[pd[idx].second])
            sum += a[pd[idx].second];

        for (auto j : era)
            st.erase(j);   
        while (st.size() && pd[idx].first >= st.begin()->first)
            st.erase(st.begin());
        while (ind[pd[idx].second] < pos[pd[idx].second].size() && pos[pd[idx].second][ind[pd[idx].second]] <= pd[idx].first) 
            ind[pd[idx].second] ++;
        if (ind[pd[idx].second] < pos[pd[idx].second].size())
            st.insert({pos[pd[idx].second][ind[pd[idx].second]], pd[idx].second});
        idx ++;
    }
    cout << now + sum << endl;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3592kb

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: 3620kb

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'