This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |