Submission #1232976

#TimeUsernameProblemLanguageResultExecution timeMemory
1232976TadijaSebezDungeon 3 (JOI21_ho_t5)C++20
11 / 100
4094 ms2020 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; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%i %i",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         scanf("%i",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
Main.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%i",&b[i]);
      |         ~~~~~^~~~~~~~~~~~
Main.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf("%i %i %i",&s,&t,&u);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...