Submission #308797

# Submission time Handle Problem Language Result Execution time Memory
308797 2020-10-02T00:28:10 Z nikatamliani Bigger segments (IZhO19_segments) C++14
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#define f first
#define s second 
#define ll long long 
using namespace std;
const int N = 5e5 + 10;
pair < int, ll > dp[N];
ll sum[N], n;
int main() {
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> sum[i], sum[i] += sum[i - 1];
    for(int i = 1; i <= n; ++i) {
        // int l = 1, r = i, ans = 1;
        // while(r >= l) {
        //     int m = l + r >> 1;
        //     if(sum[i] - sum[m - 1] >= dp[m - 1].s) {
        //         l = m + 1;
        //         ans = m;
        //     } else {
        //         r = m - 1; 
        //     }
        // }
        // dp[i].f = dp[ans - 1].f + 1;
        // dp[i].s = sum[i] - sum[ans - 1];
        for(int j = 1; j < i; ++j) {
            if(sum[i] - sum[j] >= dp[j].s) {
                if(dp[i].f == dp[j].f + 1) {
                    dp[i].s = min(dp[i].s, sum[i] - sum[j]);
                } 
                if(dp[i].f < dp[j].f + 1) {
                    dp[i].s = sum[i] - sum[j];
                }
                dp[i].f = max(dp[i].f, dp[j].f + 1);
            }
        }
        
    }
    cout << dp[n].f << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -