답안 #507275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
507275 2022-01-12T10:26:23 Z CyberSleeper Potatoes and fertilizers (LMIO19_bulves) C++14
34 / 100
91 ms 14792 KB
#include <bits/stdc++.h>
#define fastio      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x)    cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back
#define ll          long long
#define ull         unsigned long long
#define pii         pair<int, int>
#define pll         pair<ll, ll>
#define ld          long double
#define nl          '\n'
#define tb          '\t'
#define sp          ' '
using namespace std;

const int MX=500005, MOD=998244353, BLOCK=327, INF=1e9+7;
const ll INFF=1e18+7;
const ld ERR=1e-7, pi=3.14159265358979323846;

ll N, ans=INFF, A, B, tot, pref[MX], suff, DP[MX];

int main(){
    fastio;
    cin >> N;
    for(int i=1; i<=N; i++){
        cin >> A >> B;
        pref[i]=pref[i-1]+A-B;
        DP[i]=DP[i-1]+abs(pref[i]);
    }
    if(!pref[N]){
        cout << DP[N];
        exit(0);
    }
    for(int i=N; i>0; i--){
        suff+=abs(pref[i]-1);
        ans=min(ans, DP[i-1]+suff);
    }
    cout << ans << nl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 9 ms 1348 KB Output is correct
5 Correct 12 ms 2500 KB Output is correct
6 Correct 39 ms 7476 KB Output is correct
7 Correct 87 ms 14748 KB Output is correct
8 Correct 64 ms 12884 KB Output is correct
9 Correct 65 ms 12260 KB Output is correct
10 Correct 46 ms 10060 KB Output is correct
11 Correct 46 ms 10076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 9 ms 1348 KB Output is correct
5 Correct 12 ms 2500 KB Output is correct
6 Correct 39 ms 7476 KB Output is correct
7 Correct 87 ms 14748 KB Output is correct
8 Correct 64 ms 12884 KB Output is correct
9 Correct 65 ms 12260 KB Output is correct
10 Correct 46 ms 10060 KB Output is correct
11 Correct 46 ms 10076 KB Output is correct
12 Correct 20 ms 3916 KB Output is correct
13 Correct 47 ms 9004 KB Output is correct
14 Correct 91 ms 14792 KB Output is correct
15 Correct 77 ms 12944 KB Output is correct
16 Correct 63 ms 12308 KB Output is correct
17 Correct 48 ms 10064 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 320 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 320 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 320 KB Output isn't correct
5 Halted 0 ms 0 KB -