Submission #4036579


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	ll N , K;
	cin >> N >> K;
	vector<ll> a(N+1,0),s(N+1,0),allb(N+1,0);
	FOR(i,1,N+1){
		cin >> a[i];
		s[i] = s[i-1] + max(a[i],0ll);
		allb[i] = allb[i-1] + a[i];
	}
	ll ans = -INF;
	FOR(i,1,N-K+2){
		ans = max(ans,s[N]-s[i+K-1]+s[i-1]+max(0ll,allb[i+K-1]-allb[i-1]));
	}
	cout << ans << endl;
}

Submission Info

Submission Time
Task B - Contiguous Repainting
User kenta2997
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1243 Byte
Status AC
Exec Time 13 ms
Memory 2560 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 26
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 256 KB
0_01.txt AC 1 ms 256 KB
0_02.txt AC 1 ms 256 KB
0_03.txt AC 1 ms 256 KB
1_00.txt AC 1 ms 256 KB
1_01.txt AC 1 ms 256 KB
1_02.txt AC 1 ms 256 KB
1_03.txt AC 8 ms 2560 KB
1_04.txt AC 13 ms 2560 KB
1_05.txt AC 13 ms 2560 KB
1_06.txt AC 12 ms 2560 KB
1_07.txt AC 13 ms 2560 KB
1_08.txt AC 13 ms 2560 KB
1_09.txt AC 13 ms 2560 KB
1_10.txt AC 12 ms 2560 KB
1_11.txt AC 13 ms 2560 KB
1_12.txt AC 12 ms 2560 KB
1_13.txt AC 13 ms 2560 KB
1_14.txt AC 12 ms 2560 KB
1_15.txt AC 13 ms 2560 KB
1_16.txt AC 13 ms 2560 KB
1_17.txt AC 12 ms 2560 KB
1_18.txt AC 13 ms 2560 KB
1_19.txt AC 12 ms 2560 KB
1_20.txt AC 13 ms 2560 KB
1_21.txt AC 13 ms 2560 KB