AtCoder Beginner Contest 062

Submission #1338045

Source codeソースコード

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define EREP(i,n) for(int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#define BEG cout<<"D::";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#define BEG {}
#endif
const int MOD = 1000000007;
const ll INF = 50000000000000000;


    ll N,a[500000];
    ll f[500000],b[500000];
    ll ans=-INF;
    ll front,back;
    ll cnt=0;
    priority_queue<ll ,vector<ll>, greater<ll> > F;
    priority_queue<ll> B;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,3*N){
      cin>>a[i];
      if(i<N){
        F.push(a[i]);
        front+=a[i];
      }
    }
    FOR(i,N-1,N*2){

    if(N-1!=i){
        F.push(a[i]);
        front+=a[i];
        front-=F.top();
        F.pop();
    }
      f[cnt]=front;
      cnt++;
      DEB(i)DEB(a[i])DEB(front)DEB(cnt)END
    }
    cnt=0;
    END
    for(int i=N*3-1;N<=i;i--){
      if(i>=2*N){
        B.push(a[i]);
        back+=a[i];
        if(i==2*N){
            b[cnt]=back;
            cnt++;
        }
      }else{
        back+=a[i];
        B.push(a[i]);
        back-=B.top();
        B.pop();
        b[cnt]=back;
        cnt++;
      }
     DEB(i)DEB(a[i])DEB(back)DEB(cnt)END
    }
    END
    REP(i,cnt){
        DEB(i)DEB(cnt)DEB(f[i])DEB(b[cnt-i-1])END
      ans=max(ans,(f[i]-b[cnt-i-1]));
    }
    cout << ans << endl;

    return 0;
}

//ABC 062 D-3N Numbers

Submission

Task問題 D - 3N Numbers
User nameユーザ名 Nafmo
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 500
Source lengthソースコード長 1899 Byte
File nameファイル名
Exec time実行時間 59 ms
Memory usageメモリ使用量 10996 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_00.txt,0_01.txt,0_02.txt
Subtask 300 / 300 0_00.txt,0_01.txt,0_02.txt,1_00.txt,1_01.txt,1_02.txt,1_03.txt,1_04.txt,1_05.txt,1_06.txt,1_07.txt,1_08.txt,1_09.txt,1_10.txt,1_11.txt,1_12.txt,1_13.txt,1_14.txt,1_15.txt,1_16.txt,1_17.txt,1_18.txt,1_19.txt,1_20.txt,1_21.txt,1_22.txt,1_23.txt
All 200 / 200 0_00.txt,0_01.txt,0_02.txt,1_00.txt,1_01.txt,1_02.txt,1_03.txt,1_04.txt,1_05.txt,1_06.txt,1_07.txt,1_08.txt,1_09.txt,1_10.txt,1_11.txt,1_12.txt,1_13.txt,1_14.txt,1_15.txt,1_16.txt,1_17.txt,1_18.txt,1_19.txt,1_20.txt,1_21.txt,1_22.txt,1_23.txt,2_00.txt,2_01.txt,2_02.txt,2_03.txt,2_04.txt,2_05.txt,2_06.txt,2_07.txt,2_08.txt,2_09.txt,2_10.txt,2_11.txt,2_12.txt,2_13.txt,2_14.txt,2_15.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_00.txt AC 2 ms 4352 KB
0_01.txt AC 2 ms 4352 KB
0_02.txt AC 2 ms 4352 KB
1_00.txt AC 2 ms 4352 KB
1_01.txt AC 2 ms 4352 KB
1_02.txt AC 2 ms 4352 KB
1_03.txt AC 2 ms 4352 KB
1_04.txt AC 2 ms 4352 KB
1_05.txt AC 2 ms 4352 KB
1_06.txt AC 2 ms 4352 KB
1_07.txt AC 2 ms 4352 KB
1_08.txt AC 2 ms 4352 KB
1_09.txt AC 2 ms 4352 KB
1_10.txt AC 2 ms 4352 KB
1_11.txt AC 2 ms 4352 KB
1_12.txt AC 2 ms 4352 KB
1_13.txt AC 2 ms 4352 KB
1_14.txt AC 2 ms 4352 KB
1_15.txt AC 2 ms 4352 KB
1_16.txt AC 2 ms 4352 KB
1_17.txt AC 2 ms 4352 KB
1_18.txt AC 2 ms 4352 KB
1_19.txt AC 2 ms 4352 KB
1_20.txt AC 2 ms 4352 KB
1_21.txt AC 2 ms 4352 KB
1_22.txt AC 2 ms 4352 KB
1_23.txt AC 2 ms 4352 KB
2_00.txt AC 29 ms 10996 KB
2_01.txt AC 45 ms 10996 KB
2_02.txt AC 41 ms 10996 KB
2_03.txt AC 43 ms 10996 KB
2_04.txt AC 42 ms 10996 KB
2_05.txt AC 42 ms 10996 KB
2_06.txt AC 42 ms 10996 KB
2_07.txt AC 42 ms 10996 KB
2_08.txt AC 35 ms 10868 KB
2_09.txt AC 34 ms 10868 KB
2_10.txt AC 35 ms 10868 KB
2_11.txt AC 34 ms 10868 KB
2_12.txt AC 58 ms 10868 KB
2_13.txt AC 58 ms 10996 KB
2_14.txt AC 59 ms 10868 KB
2_15.txt AC 58 ms 10868 KB