Submission #991312

# Submission time Handle Problem Language Result Execution time Memory
991312 2024-06-01T21:55:33 Z vjudge1 Feast (NOI19_feast) C++17
18 / 100
1000 ms 7388 KB
#include<bits/stdc++.h>
#include<ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define Fast ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define int long long
template<class T> using ordered_set = tree<T, null_type , less<T> ,rb_tree_tag , tree_order_statistics_node_update> ;
typedef long long ll;
const int N=3e5+3,LG=__lg(N)+2,M=21,MOD=998244353,inf=1e15;
int dp[2][N];
void solve() {
    int n,k;
    cin>>n>>k;
    vector<int>v(n+3);
    for (int i = 2; i <=n+1 ; ++i) {
        cin>>v[i];
        v[i]+=v[i-1];
    }
    for (int i = 1; i <=k ; ++i) {
        int best=-inf;
        for (int r = 2; r<=n+1 ; ++r) {
            dp[i&1][r]=(best=max(best,dp[(i-1)&1][r-2]-v[r-1]))+v[r];
        }
    }
    cout<<*max_element(dp[k&1],dp[k&1]+N)<<'\n';

}
signed main() {
    Fast;
    int tc = 1;
    //cin >> tc;
    for (int i = 1; i <= tc; ++i) {
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1026 ms 7256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 4952 KB Output is correct
2 Correct 14 ms 5212 KB Output is correct
3 Correct 13 ms 4956 KB Output is correct
4 Execution timed out 1100 ms 7388 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 5204 KB Output is correct
2 Correct 21 ms 5068 KB Output is correct
3 Correct 28 ms 4944 KB Output is correct
4 Correct 23 ms 4956 KB Output is correct
5 Correct 22 ms 5212 KB Output is correct
6 Correct 27 ms 5204 KB Output is correct
7 Correct 22 ms 5212 KB Output is correct
8 Correct 22 ms 5212 KB Output is correct
9 Correct 22 ms 5120 KB Output is correct
10 Correct 22 ms 5108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1026 ms 7256 KB Time limit exceeded
2 Halted 0 ms 0 KB -