이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |