QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#717859#9528. New Energy VehicleLeoGRE 0ms3752kbC++232.9kb2024-11-06 19:07:532024-11-06 19:07:57

Judging History

This is the latest submission verdict.

  • [2024-11-06 19:07:57]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 3752kb
  • [2024-11-06 19:07:53]
  • Submitted

answer

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <numeric>

#define ll              long long 
#define all(v)          v.begin(),v.end()
#define ld              long double
#define pll             std::pair<ll,ll>
#define pi              std::pair<int,int>
#define vi              std::vector<int>
#define vll             std::vector<ll>
#define len(x)          (int)x.size()
#define vec(T)          std::vector<T>


template<typename T, typename = void>
struct is_printable : std::false_type {};

template<typename T>
struct is_printable<T, std::void_t<decltype(std::declval<std::ostream&>() << std::declval<T>())>> : std::true_type {};
template <typename T>
void print(const std::pair<T, T>& pair) {
    std::cout << "(" << pair.first << ", " << pair.second << ")";
}

// General print function
template <typename T>
void print(const T& val) {
    std::cout << val;
}

// Print function for std::vector
template <typename T>
void print(const std::vector<T>& vec) {
    std::cout << '[';
    int n = vec.size();
    for (int i = 0; i < n; i++) {
        print(vec[i]);
        if (i < n - 1) {
            std::cout << ",";
        }
    }
    std::cout << ']' << '\n';
}

// Variadic template print function
template<typename T, typename... Args>
void print(const T& t, const Args&... args) {
    print(t);
    std::cout << (is_printable<T>::value ? ' ' : '\0');
    print(args...);
    if (sizeof...(args) == 1 && is_printable<T>::value) std::cout << '\n';

}

void solve(){
    int n, m;
    std::cin >> n >> m;
    vll a(n), x(n), t(n), fuel(n);
    vec(std::deque<int>) mp(n);
    std::priority_queue<pll, vec(pll), std::greater<pll>> pq;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    fuel = a;
    for (int i = 0; i < m; i++) {
        std::cin >> x[i] >> t[i];
        mp[--t[i]].push_back(x[i]);
    }
    for (int i = 0; i < n; i++) {
        mp[i].push_back(2e9);
        pq.push({mp[i].front(), i});
    }
    int cur = 0;
    for (int i = 0; i < m; i++) {
        while (!pq.empty() && cur < x[i]) {
            auto [_, ind] = std::move(pq.top());
            pq.pop();
            ll tmp = std::min(cur + a[ind], x[i]);
            a[ind] -= tmp - cur;
            cur = tmp;
            if (a[ind] && mp[ind].front() > x[i]) {
                pq.push({mp[ind].front(), ind});
            }
        }
        if (cur < x[i]) break;
        if (mp[t[i]].size() > 1) mp[t[i]].pop_front();
        a[t[i]] = fuel[t[i]];
        pq.push({mp[t[i]].front(), t[i]});
    }
    for (int i = 0; i < n; i++) {
        cur += a[i];
    }
    std::cout << cur << std::endl;



    

}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t = 1;
    std::cin >> t;
    while (t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

9
11
4
11
999999999
2000000000

result:

ok 6 lines

Test #3:

score: -100
Runtime Error

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:


result: