QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#705116#9528. New Energy Vehicleadivse#WA 11ms71368kbC++203.4kb2024-11-02 22:12:242024-11-02 22:12:26

Judging History

This is the latest submission verdict.

  • [2024-11-02 22:12:26]
  • Judged
  • Verdict: WA
  • Time: 11ms
  • Memory: 71368kb
  • [2024-11-02 22:12:24]
  • Submitted

answer

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#define endl '\n'
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define rep2(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
template<typename T>
void cc(vector<T> tem) { for (auto x : tem) cout << x << ' '; cout << endl; }
void cc(int a) { cout << a << endl; }
void cc(int a, int b) { cout << a << ' ' << b << endl; }
void cc(int a, int b, int c) { cout << a << ' ' << b << ' ' << c << endl; }
void kuaidu() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
inline int max(int a, int b) { if (a < b) return b; return a; }
inline int min(int a, int b) { if (a < b) return a; return b; }
void cmax(int& a, const int b) { if (b > a) a = b; }
void cmin(int& a, const int b) { if (b < a) a = b; }
using PII = pair<int, int>;
using i128 = __int128;

//--------------------------------------------------------------------------------
const int N = 1e5 + 10;
const int M = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e16;
int n, m, T;
int A[N], B[N];
bool flag[N];
//--------------------------------------------------------------------------------

struct node {
    int id;
    int val;
    bool operator<(const node& q1)const {
        return q1.id < id;
    }
};
priority_queue<node> F;
// vector<int> g[N];
queue<int> g[N];
node D[N];
void dfs() {



}

signed main() {
    kuaidu();
    T = 1;
    cin >> T;
    while (T--) {
        cin >> n >> m;

        rep(i, 1, n) {
            while (!g[i].empty()) g[i].pop();
        }
        rep(i, 1, m) {
            flag[i] = 0;
        }
        rep(i, 1, n) {
            cin >> A[i];
            B[i] = A[i];
        }
        while (!F.empty()) F.pop();

        rep(i, 1, m) {
            int x, t;
            cin >> x >> t;
            // F.push({ t,x });
            D[i] = { x,t };
            g[t].push(x);
        }
        sort(D + 1, D + m + 1, [&](node q1, node q2) {
            return q1.id < q2.id;
            });

        rep(i, 1, m) {
            if (flag[i]) continue;
            flag[i] = 1;
            F.push({ D[i] });
        }
        int sum = 0;
        rep(i, 1, n) {
            if (flag[i]) continue;
            flag[i] = 1;
            F.push({ INF - i, i });
        }
        int pos = 0;
        int ans = 0;
        D[m + 1] = { INF,0 };
        for (int i = 1; i <= m + n; i++) {
            int to = D[i].id;
            while ((!F.empty()) and pos + A[F.top().val] < to) {
                pos += A[F.top().val];
                A[F.top().val] = 0;
                F.pop();
            }

            if (F.empty()) {
                ans = pos;
                break;
            }

            int val = F.top().val, id = F.top().id;
            A[F.top().val] -= to - pos;
            pos = to;

            if (A[F.top().val] == 0 || F.top().id <= pos) F.pop();
            // F.pop();
            if (g[D[i].val].size()) g[D[i].val].pop();


            if (g[D[i].val].size()) {
                A[D[i].val] = B[D[i].val];
                F.push({ g[D[i].val].front(), D[i].val });
            }
            else {
                A[D[i].val] = B[D[i].val];
                F.push({ INF - 1,D[i].val });
            }

        }
        cout << ans << endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 71368kb

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: 11ms
memory: 71176kb

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:

4
11
4
11
999999999
2000000000

result:

wrong answer 1st lines differ - expected: '9', found: '4'