QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#678348#9528. New Energy Vehicleucup-team045#WA 0ms3748kbC++201.7kb2024-10-26 14:42:102024-10-26 14:42:21

Judging History

This is the latest submission verdict.

  • [2024-10-26 14:42:21]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3748kb
  • [2024-10-26 14:42:10]
  • Submitted

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<set>
using namespace std;
using LL = long long;

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int T;
    cin >> T;
    while(T--){
        int n, m;
        cin >> n >> m;
        vector<int> a(n + 1);
        for(int i = 1; i <= n; i++) cin >> a[i];
        vector<LL> x(m + 1);
        vector<int> t(m + 1);
        for(int i = 1; i <= m; i++){
            cin >> x[i] >> t[i];
        }

        auto check = [&](LL mid){
            vector<int> last(n + 1, m + 1);
            int pos = m;
            while(mid <= x[pos]) pos--;
            vector<LL> s1(m + 1), s2(m + 1);
            for(int i = pos; i >= 0; i--){
                LL len = mid - x[i];
                s1[i] += len;
                if (i == 0){
                    for(int j = 1; j <= n; j++){
                        s2[last[j] - 1] += a[j];
                    }
                }
                else{
                    s2[last[t[i]] - 1] += a[t[i]];
                }
                last[t[i]] = i;
                mid = x[i];
            }
            LL remain = 0;
            for(int i = m; i >= 0; i--){
                if (s2[i] + remain < s1[i]){
                    return false;
                }
                remain = s2[i] + remain - s1[i];
            }
            return true;
        };

        LL l = 0, r = 1e15;
        while(l < r){
            LL mid = (l + r + 1) / 2;
            if (check(mid)) l = mid;
            else r = mid - 1;
        }
        cout << r << '\n';
    }

}

詳細信息

Test #1:

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

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

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:

10
11
4
11
1999999998
2000000000

result:

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