QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#683509#9528. New Energy Vehiclekano07WA 1ms5688kbC++141.7kb2024-10-27 21:34:132024-10-27 21:34:13

Judging History

This is the latest submission verdict.

  • [2024-10-27 21:34:13]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5688kb
  • [2024-10-27 21:34:13]
  • Submitted

answer

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using db = long double;
class JudTime {
public:
    chrono::time_point<chrono::high_resolution_clock> start, end;
    JudTime() : start(chrono::high_resolution_clock::now()) {}
    ~JudTime() {
        end = chrono::high_resolution_clock::now();
        cerr << fixed << setprecision(6) << chrono::duration<double>(end - start).count()
             << " seconds" << endl;
    }
};
const int N = 1e5 + 5;
ll a[N];
ll last[N];
pll v[N];   // first位置,second充电目标
void solve() {
    int n, m;
    cin >> n >> m;
    ll all = 0;
    for (int i = 1; i <= n; i++) {
        last[i] = 0;
        cin >> a[i];
        all += a[i];
    }
    for (int i = 1; i <= m; i++) cin >> v[i].first >> v[i].second;
    sort(v + 1, v + 1 + m, [](pll x, pll y) {
        if (x.first == y.first) return a[x.second] > a[y.second];
        return x.first < y.first;
    });
    v[0] = {0, 0};
    ll sum = 0;   //欠费数
    for (ll i = 1; i <= m; i++) {
        ll dis = v[i].first - v[i - 1].first;   //路程
        ll get = min(v[i].first - last[v[i].second], a[v[i].second]);
        if (sum + dis - get > all) {
            cout << v[i - 1].first + all - sum << endl;
            return;
        }
        last[v[i].second] = v[i].first;
        sum += dis;   //欠费数
        sum = max(0ll, sum - get);
    }
    cout << v[m].first + all - sum << endl;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 5688kb

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
10
11
1999999998
2000000000

result:

wrong answer 3rd lines differ - expected: '4', found: '10'