QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#698853#9528. New Energy VehiclelvliangWA 56ms13152kbC++142.2kb2024-11-01 22:40:512024-11-01 22:40:51

Judging History

This is the latest submission verdict.

  • [2024-11-01 22:40:51]
  • Judged
  • Verdict: WA
  • Time: 56ms
  • Memory: 13152kb
  • [2024-11-01 22:40:51]
  • Submitted

answer

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#define x first
#define y second

using namespace std;
typedef long long LL;
const int N = 1e5 + 10;

struct battery {
    LL rem;
    int idx;
    bool operator < (const battery& W) const {
        return idx > W.idx;
    } 
};
LL a[N];
pair<LL, LL> pa[N];
int ne_st[N];
int vis[N];

void solve() {
    memset(vis, 0, sizeof vis);
    memset(ne_st, 0, sizeof ne_st);
    priority_queue<battery> pq;
    int n, m;
    scanf("%d%d", &n, &m);

    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
    }

    for (int i = 1; i <= m; i++) {
        scanf("%lld%lld", &pa[i].x, &pa[i].y);
    }
    sort(pa + 1, pa + m + 1);
    for (int i = m; i; i--) {
        int j = pa[i].y;
        if (!vis[j]) vis[j] = i;
        else {
            ne_st[i] = vis[j];
            vis[j] = i;
        }
    }
    
    LL extra = 0;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            extra += a[i];
            continue;
        }
        pq.push({ a[i], vis[i] });
    }

    for (int i = 1; i <= m; i++) {
        LL dis = pa[i].x - pa[i - 1].x;
        LL oil = 0;
        while (pq.size()) {
            oil += pq.top().rem;
            if (oil > dis) {
                auto tmp = pq.top();
                if (tmp.idx == i) {
                    pq.pop();
                } else {
                    tmp.rem = oil - dis;
                    pq.push(tmp);
                }
                break;
            }
            pq.pop();
            if (oil == dis) break;
        }

        if (dis > oil) {
            if (oil + extra < dis) {
                printf("%lld\n", pa[i - 1].x + oil + extra);
                return;
            }
            extra += oil - dis;
        }
        if (!ne_st[pa[i].y]) {
            extra += a[pa[i].y];
        } else {
            pq.push({ a[pa[i].y], ne_st[i] });
        }
    }
    while (pq.size()) {
        extra += pq.top().rem;
        pq.pop();
    }
    printf("%lld\n", pa[m].x + extra);
}

int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6192kb

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: 0
Accepted
time: 1ms
memory: 4900kb

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
11
4
11
999999999
2000000000

result:

ok 6 lines

Test #3:

score: -100
Wrong Answer
time: 56ms
memory: 13152kb

input:

10
230 8042
599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...

output:

77180371
43178855
14507960
69273208
25178697
175655806
3039902
174907448
4633885
3327258

result:

wrong answer 1st lines differ - expected: '1543020', found: '77180371'