Submission #4031342
Source Code Expand
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <string> #include <iomanip> using namespace std; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++) typedef long long ll; const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; int main(){ int n,k; vector<int> a(n); cin >> n >> k; rep(i,n){ cin >> a[i]; } vector<ll> sum(n,a[0]),best_sum(n,max(0,a[0])); for(int i=1;i<n;i++){ sum[i]=sum[i-1]+a[i]; best_sum[i]=best_sum[i-1]+max(0,a[i]); } ll ans = -1e9; for(int i=0;i+k<=n;i++){ ll tmp=0,plus=0; if(i==0){ tmp = max(0LL,sum[k-1]); plus = best_sum[n-1]-best_sum[k-1]; }else{ tmp = max(0LL,sum[i+k-1]-sum[i-1]); plus = best_sum[n-1]-(best_sum[i+k-1]-best_sum[i-1]); } ll score = tmp+plus; ans = max(ans,score); } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Contiguous Repainting |
User | rokahikou |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1055 Byte |
Status | RE |
Exec Time | 116 ms |
Memory | 384 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 400 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 1 ms | 384 KB |
0_01.txt | AC | 1 ms | 384 KB |
0_02.txt | AC | 1 ms | 384 KB |
0_03.txt | AC | 1 ms | 384 KB |
1_00.txt | AC | 1 ms | 384 KB |
1_01.txt | AC | 1 ms | 384 KB |
1_02.txt | AC | 1 ms | 384 KB |
1_03.txt | RE | 106 ms | 384 KB |
1_04.txt | RE | 113 ms | 384 KB |
1_05.txt | RE | 115 ms | 384 KB |
1_06.txt | RE | 112 ms | 384 KB |
1_07.txt | RE | 113 ms | 384 KB |
1_08.txt | RE | 113 ms | 384 KB |
1_09.txt | RE | 112 ms | 384 KB |
1_10.txt | RE | 113 ms | 384 KB |
1_11.txt | RE | 113 ms | 384 KB |
1_12.txt | RE | 113 ms | 384 KB |
1_13.txt | RE | 113 ms | 384 KB |
1_14.txt | RE | 112 ms | 384 KB |
1_15.txt | RE | 116 ms | 384 KB |
1_16.txt | RE | 113 ms | 384 KB |
1_17.txt | RE | 112 ms | 384 KB |
1_18.txt | RE | 113 ms | 384 KB |
1_19.txt | RE | 112 ms | 384 KB |
1_20.txt | RE | 112 ms | 384 KB |
1_21.txt | RE | 112 ms | 384 KB |