Submission #144365

# Submission time Handle Problem Language Result Execution time Memory
144365 2019-08-16T18:05:54 Z brcode Potatoes and fertilizers (LMIO19_bulves) C++14
24 / 100
561 ms 20088 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 4 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 38 ms 2296 KB Output is correct
5 Correct 74 ms 4292 KB Output is correct
6 Correct 284 ms 10244 KB Output is correct
7 Correct 561 ms 20088 KB Output is correct
8 Correct 453 ms 19960 KB Output is correct
9 Correct 419 ms 20088 KB Output is correct
10 Correct 276 ms 19928 KB Output is correct
11 Correct 277 ms 19832 KB Output is correct
# Verdict Execution time Memory 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 38 ms 2296 KB Output is correct
5 Correct 74 ms 4292 KB Output is correct
6 Correct 284 ms 10244 KB Output is correct
7 Correct 561 ms 20088 KB Output is correct
8 Correct 453 ms 19960 KB Output is correct
9 Correct 419 ms 20088 KB Output is correct
10 Correct 276 ms 19928 KB Output is correct
11 Correct 277 ms 19832 KB Output is correct
12 Incorrect 144 ms 5284 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 4 ms 504 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 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 -
# Verdict Execution time Memory 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 -