답안 #1022529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1022529 2024-07-13T16:38:53 Z Aiperiii Dungeon 3 (JOI21_ho_t5) C++14
0 / 100
4000 ms 6828 KB
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
signed main(){
    int n,m;
    cin>>n>>m;
    vector <int> a(n+2),pr(n+1);
    vector <int> b(n+1),r(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pr[i]=pr[i-1]+a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
    }
    stack <int> st;
    for(int i=1;i<=n+1;i++){
        while(!st.empty() && b[st.top()]>=b[i]){
            r[st.top()]=i-1;
            st.pop();
        }
        st.push(i);
    }
  
    while(m--){
        int s,t,u;
        cin>>s>>t>>u;
        bool ok=1;
        int en=0,ans=0,ls=-1;
        for(int i=s;i<t;i++){
            int sum=pr[min(t-1,r[i])]-pr[i-1];
            sum=max(0ll,sum-en);
            ans+=min(sum,u-en)*b[i];
            if(min(sum,u-en)>0)ls=b[i];
            en+=min(sum,u-en);
            en-=a[i];
            if(en<0){
                ok=0;
            }
        }
        
        if(ok)cout<<ans<<"\n";
        else cout<<-1<<"\n";
        
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:33:24: warning: variable 'ls' set but not used [-Wunused-but-set-variable]
   33 |         int en=0,ans=0,ls=-1;
      |                        ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1791 ms 2608 KB Output is correct
2 Correct 2857 ms 2608 KB Output is correct
3 Correct 1646 ms 3196 KB Output is correct
4 Correct 1801 ms 2644 KB Output is correct
5 Correct 2318 ms 2712 KB Output is correct
6 Execution timed out 4069 ms 6828 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4019 ms 6736 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -