Submission #8576313


Source Code Expand

Copy
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <tuple>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
    ll n, a[200020], s = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        s += a[i];
    }

    ll t = 0, ans = 1e18;
    for (int i = 0; i < n; i++) {
        t += a[i];
        ans = min(ans, abs(2 * t - s));
    }
    cout << ans << endl;

    

}

Submission Info

Submission Time
Task B - Iron Bar Cutting
User ast210
Language C++14 (GCC 5.4.1)
Score 200
Code Size 529 Byte
Status AC
Exec Time 86 ms
Memory 1792 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 2
AC × 20
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
in01.txt AC 1 ms 256 KB
in02.txt AC 1 ms 256 KB
in03.txt AC 1 ms 256 KB
in04.txt AC 1 ms 256 KB
in05.txt AC 1 ms 256 KB
in06.txt AC 1 ms 256 KB
in07.txt AC 83 ms 1792 KB
in08.txt AC 83 ms 1792 KB
in09.txt AC 83 ms 1792 KB
in10.txt AC 83 ms 1792 KB
in11.txt AC 83 ms 1792 KB
in12.txt AC 83 ms 1792 KB
in13.txt AC 83 ms 1792 KB
in14.txt AC 83 ms 1792 KB
in15.txt AC 83 ms 1792 KB
in16.txt AC 83 ms 1792 KB
in17.txt AC 86 ms 1792 KB
in18.txt AC 1 ms 256 KB
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB