Submission #4620312


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,x,a,tmp,ans;

main() {
    cin >> n >> x >> tmp,n--;
    rep(i,n) {
        cin >> a;
        ans += max((int)0,tmp+a-x);
        tmp = max((int)0,a-max((int)0,tmp+a-x));
    }
    cout << ans << endl;
}

Submission Info

Submission Time
Task C - Boxes and Candies
User kr
Language C++14 (GCC 5.4.1)
Score 300
Code Size 834 Byte
Status AC
Exec Time 44 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 20
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.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
Case Name Status Exec Time Memory
0_00.txt AC 1 ms 256 KB
0_01.txt AC 1 ms 256 KB
0_02.txt AC 1 ms 256 KB
0_03.txt AC 1 ms 256 KB
1_00.txt AC 1 ms 256 KB
1_01.txt AC 1 ms 256 KB
1_02.txt AC 1 ms 256 KB
1_03.txt AC 1 ms 256 KB
1_04.txt AC 17 ms 256 KB
1_05.txt AC 17 ms 256 KB
1_06.txt AC 43 ms 256 KB
1_07.txt AC 44 ms 256 KB
1_08.txt AC 40 ms 256 KB
1_09.txt AC 40 ms 256 KB
1_10.txt AC 40 ms 256 KB
1_11.txt AC 40 ms 256 KB
1_12.txt AC 39 ms 256 KB
1_13.txt AC 40 ms 256 KB
1_14.txt AC 40 ms 256 KB
1_15.txt AC 40 ms 256 KB