# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1232976 | TadijaSebez | Dungeon 3 (JOI21_ho_t5) | C++20 | 4094 ms | 2020 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200050;
int a[N],b[N];
int main(){
int n,m;
scanf("%i %i",&n,&m);
for(int i=1;i<=n;i++){
scanf("%i",&a[i]);
}
for(int i=1;i<=n;i++){
scanf("%i",&b[i]);
}
while(m--){
int s,t,u;
scanf("%i %i %i",&s,&t,&u);
deque<pair<int,int>> cand;
int sum=0;
ll ans=0;
bool ok=true;
for(int i=s;i<t;i++){
while(cand.size() && cand.back().first>=b[i]){
sum-=cand.back().second;
cand.pop_back();
}
cand.push_back({b[i],u-sum});
sum=u;
if(a[i]>u){
ok=false;
break;
}
int need=a[i];
sum-=need;
//printf("Consume %i\n",a[i]);
while(cand.size() && cand.front().second<=need){
ans+=(ll)cand.front().first*cand.front().second;
//printf("Buy (bi:%i amount:%i)\n",cand.front().first,cand.front().second);
need-=cand.front().second;
cand.pop_front();
}
if(need>0){
ans+=(ll)cand.front().first*need;
//printf("Buy (bi:%i amount:%i)\n",cand.front().first,need);
cand.front().second-=need;
}
}
printf("%lld\n",ok?ans:(ll)-1);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |