제출 #1092326

#제출 시각아이디문제언어결과실행 시간메모리
1092326PagodePaivaDungeon 3 (JOI21_ho_t5)C++17
0 / 100
273 ms672 KiB
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 3010;
int a[N], b[N];

int32_t main(){
    int n, m;
    cin >> n >> m;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    }
    for(int i = 1;i <= n;i++){
        cin >> b[i];
    }
    while(m--){
        int x, y, u;
        cin >> x >> y >> u;
        priority_queue <pair <int, int>> pq;
        bool aux = true;
        int res = 0;
        for(int i = x;i < y;i++){
            if(a[i] > u){
                aux = false;
                break;
            }
            pq.push({-b[i], u});
            int tot = a[i];
            while(!pq.empty()){
                auto [valor, qtd] = pq.top();
                pq.pop();
                valor *= -1;
                if(tot >= qtd){
                    tot -= qtd;
                    res += valor*qtd;
                }
                else{
                    res += valor*tot;
                    pq.push({-valor, qtd-tot});
                    break;
                }
            }
        }
        if(!aux){
            cout << -1 << '\n';
        }
        else{
            cout << res << '\n';
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...