Submission #995363

# Submission time Handle Problem Language Result Execution time Memory
995363 2024-06-08T23:18:39 Z PagodePaiva Jobs (BOI24_jobs) C++17
0 / 100
111 ms 142032 KB
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 100010;

int pai[N], val[N];
stack <pair <int, int>> s[N];

int32_t main(){
    int n, c;
    cin >> n >> c;
    vector<int> aux;
    int con = 0;
    for(int i = 1;i <= n;i++){
        cin >> val[i] >> pai[i];
        if(pai[i] == 0){
            if(!aux.empty()){
                reverse(aux.begin(), aux.end());
                vector <pair <int, int>> res;
                int ac = 0;
                int mnac = 0;
                while(!aux.empty()){
                    //cout << aux.back() << ' ' << ac << '\n';
                    if(aux.back() + ac >= 0){
                        ac = 0;
                        res.push_back({aux.back()+ac, mnac});
                        mnac = 0;
                    }
                    else{
                        ac += aux.back();
                        mnac = min(mnac, ac);
                    }
                    aux.pop_back();
                }
                for(auto x : res){
                    //cout << x.first << ' ';
                    s[con].push(x);
                }
                con++;
            }
        }
        //cout << val[i] << ' ';
        aux.push_back(val[i]);
    }
    priority_queue <array <int, 3>> pq;
    for(int i = 0;i < con;i++){
        if(s[i].empty()) continue;
        pq.push({s[i].top().second, s[i].top().first, i});
    }
    int res = 0;
    while(!pq.empty()){
        auto [mnac, valtot, i] = pq.top();
        pq.pop();
        // cout << mnac << ' ';
        if(c + mnac < 0) break;
        res += valtot;
        c += valtot;
        s[i].pop();
        if(s[i].empty()) continue;
        pq.push({s[i].top().second, s[i].top().first, i});
    }
    cout << res << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 111 ms 142032 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 68176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 68176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 68176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 111 ms 142032 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -