제출 #857625

#제출 시각아이디문제언어결과실행 시간메모리
857625hungntFeast (NOI19_feast)C++14
12 / 100
28 ms5604 KiB
#include<bits/stdc++.h> using namespace std; const int N = 300005; int n, k; int a[N]; long long dp[2003][2003][2]; void sub3() { long long ans = 0, mx = 0, mn = 0, s = 0; for(int i = 1; i <= n; i++) { s += a[i]; mx = max(mx, s); mn = min(mn, s); ans = max(ans, mx - mn); } cout << ans; } void sub6() { long long ans=0; dp[0][0][1] = 0; dp[0][0][0] = 0; for(int i = 1; i <= n; i++) { dp[i][0][0] = 0; for(int j = 1; j <= k; j++) { dp[i][j][0] = max(dp[i - 1][j][1], dp[i - 1][j][0]); dp[i][j][1] = max(dp[i - 1][j][1], dp[i - 1][j - 1][0]) + a[i]; ans = max({ans, dp[i][j][0], dp[i][j][1]}); } } cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; int cntam = 0; long long s = 0; for(int i = 1; i <= n; i++) { cin >> a[i]; cntam += (a[i] < 0); } if(k == 1) { sub3(); return 0; } if(cntam <= 1) { long long ans = 0; for(int i = 1; i <= n; i++) if(a[i] > 0) ans += a[i]; cout << ans; return 0; } sub6(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

feast.cpp: In function 'int main()':
feast.cpp:47:15: warning: unused variable 's' [-Wunused-variable]
   47 |     long long s = 0;
      |               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...