Skip to content

Instantly share code, notes, and snippets.

@jinnatul
Created January 14, 2019 15:57
Show Gist options
  • Save jinnatul/66d097dccd43cb38a34f1d2e400d3f7d to your computer and use it in GitHub Desktop.
Save jinnatul/66d097dccd43cb38a34f1d2e400d3f7d to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
/// Typedef
typedef long long ll;
typedef int in;
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define pf1(a) printf("%lld\n",a)
#define pf2(a,b) printf("%lld %lld\n",a,b)
#define pfi1(a) printf("%d\n",a)
#define mx 1000010
#define mod 10000007
#define PI acos(-1.0)
int dr[] = {-2,-2,-1,-1,1,1,2,2};
int dc[] = {-1,1,-2,2,-2,2,-1,1};
int main() {
ll tc, num, t;
//freopen("C:\\Users\\morol\\Desktop\\Clion\\input.txt", "r", stdin);
sc2(num, tc);
ll arr[num];
ll total = 0;
for( ll i = 0; i < num; i++ ){
sc1(arr[i]); total += arr[i];
}
ll ans = 0;
for( ll i = 0; i < tc; i++ ){
ll sum = total;
for( ll j = i; j < num; j +=tc ) sum -= arr[j];
ans = max(ans, abs(sum));
}
pf1(ans);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment