結果
| 問題 | No.3017 交互浴 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-01-25 19:28:56 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 304 ms / 2,000 ms | 
| コード長 | 582 bytes | 
| コンパイル時間 | 578 ms | 
| コンパイル使用メモリ | 68,872 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2025-01-26 00:03:37 | 
| 合計ジャッジ時間 | 20,537 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge12 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 55 | 
ソースコード
#include<iostream>
#include<stack>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N;
    cin>>N;
    stack<int> st;
    st.push(2e9);
    int wb=0;
    rep(i,N){
        int H;
        cin>>H;
        int mae=0;
        while(st.top()<H){
            if(st.size()%2==0) wb-=st.top()-mae;
            mae=st.top();
            st.pop();
        }
        if(st.size()%2==0) wb-=H-mae;
        if(i%2==0) wb+=H;
        if((st.size()+i)%2) st.push(H);
        cout<<wb<<endl;
    }
}
            
            
            
        