Submission #144363

# Submission time Handle Problem Language Result Execution time Memory
144363 2019-08-16T18:02:51 Z brcode Potatoes and fertilizers (LMIO19_bulves) C++14
24 / 100
564 ms 20104 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 = 1e9;
    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;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 37 ms 2300 KB Output is correct
5 Correct 72 ms 4364 KB Output is correct
6 Correct 281 ms 10104 KB Output is correct
7 Correct 564 ms 20092 KB Output is correct
8 Correct 454 ms 19832 KB Output is correct
9 Correct 413 ms 19960 KB Output is correct
10 Correct 277 ms 19832 KB Output is correct
11 Correct 277 ms 20104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 37 ms 2300 KB Output is correct
5 Correct 72 ms 4364 KB Output is correct
6 Correct 281 ms 10104 KB Output is correct
7 Correct 564 ms 20092 KB Output is correct
8 Correct 454 ms 19832 KB Output is correct
9 Correct 413 ms 19960 KB Output is correct
10 Correct 277 ms 19832 KB Output is correct
11 Correct 277 ms 20104 KB Output is correct
12 Incorrect 142 ms 5152 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -