답안 #144366

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
144366 2019-08-16T18:09:27 Z brcode Potatoes and fertilizers (LMIO19_bulves) C++14
34 / 100
572 ms 26708 KB
#include <iostream>

using namespace std;
const long long MAXN = 5e5+5;
long long arr[MAXN];
long long dp[MAXN][3];
long long pref[MAXN];
int main(){
    long long n;
    cin>>n;
    for(long long i=1;i<=n;i++){
        long long a,b;
        cin>>a>>b;
        arr[i] = a-b;
        pref[i] = pref[i-1]+arr[i];
    }
    long long ans = 1e18;
    for(long long i=1;i<=n;i++){
        dp[i][0]=dp[i-1][0]+abs(pref[i]);
       
    }
    for(int i=n;i>=1;i--){
        dp[i][1] = dp[i+1][1]+abs(pref[i]-1);
    }
    if(pref[n] == 0){
        cout<<dp[n][0]<<endl;
        return 0;
    }
    for(int i=1;i<=n;i++){
        ans = min(ans,dp[i-1][0]+dp[i][1]);
    }
    cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 37 ms 2264 KB Output is correct
5 Correct 74 ms 4244 KB Output is correct
6 Correct 281 ms 10308 KB Output is correct
7 Correct 561 ms 20012 KB Output is correct
8 Correct 457 ms 19960 KB Output is correct
9 Correct 416 ms 19940 KB Output is correct
10 Correct 280 ms 19948 KB Output is correct
11 Correct 277 ms 19960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 37 ms 2264 KB Output is correct
5 Correct 74 ms 4244 KB Output is correct
6 Correct 281 ms 10308 KB Output is correct
7 Correct 561 ms 20012 KB Output is correct
8 Correct 457 ms 19960 KB Output is correct
9 Correct 416 ms 19940 KB Output is correct
10 Correct 280 ms 19948 KB Output is correct
11 Correct 277 ms 19960 KB Output is correct
12 Correct 142 ms 5304 KB Output is correct
13 Correct 341 ms 16176 KB Output is correct
14 Correct 572 ms 26708 KB Output is correct
15 Correct 460 ms 24828 KB Output is correct
16 Correct 425 ms 24164 KB Output is correct
17 Correct 267 ms 21896 KB Output is correct
18 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -