This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///huynhocute123///
#include<bits/stdc++.h>
using namespace std;
#define S second
#define F first
#define pii pair<int,int>
#define piii pair<int,pair<int,int>>
#define pb push_back
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define REP(i, a, b) for(int i = b; i >= a; --i)
#define ALL(v) v.begin(),v.end()
#define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
#define out(name) if(fopen(name, "w")) freopen(name, "w", stdout);
//random_device rd;
//mt19937 rng(rd());
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
//#define int long long
const int maxN = 2009;
const int mod = 1e9 + 7;
const int base = 2309;
const int MAX = 1e9+9;
const double pi = 3.14159265358979323846;
const double rad = 3.14159265358979323846 /180;
bool minimize(int &u, int v){
if(v < u){
u = v;
return 1;
}
return 0;
}
bool maximize(int &u, int v){
if(v > u){
u = v;
return 1;
}
return 0;
}
bool maximizell(long long &u, long long v){
if(v > u){
u = v;
return 1;
}
return 0;
}
bool minimizell(long long &u, long long v){
if(v < u){
u = v;
return 1;
}
return 0;
}
inline int fastPow(int a, int n){
if(n == 0) return 1;
int t = fastPow(a, n >> 1);
t = 1ll * t * t % mod;
if(n & 1) t = 1ll * t * a % mod;
return t;
}
int n , k;
long long a[maxN] , dp[maxN][maxN], g[maxN][maxN], res;
inline void solve(){
cin >> n >>k;
FOR(i, 1, n)cin >> a[i];
FOR(i, 1, n){
FOR(j, 1, k){
dp[i][j] = dp[i-1][j] + a[i];
maximizell(dp[i][j] , g[i-1][j-1] + a[i]);
maximizell(g[i][j] , g[i-1][j]);
maximizell(g[i][j] , dp[i][j]);
}
}
FOR(i, 1, k)maximizell(res, g[n][i]);
cout << res;
}
signed main(){
// freopen("name.inp","r",stdin);
// freopen("name.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
inp("task.inp");
int tc = 1;
// cin >> tc;
while( tc-- )solve();
cerr << '\n' << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << " s\n" ;
}
Compilation message (stderr)
feast.cpp: In function 'int main()':
feast.cpp:12:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~
feast.cpp:83:5: note: in expansion of macro 'inp'
83 | inp("task.inp");
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |