Source Code
/*
░██████╗░█████╗░███████╗███████╗██████╗░██╗░░░██╗
██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗╚██╗░██╔╝
╚█████╗░███████║█████╗░░█████╗░░██║░░██║░╚████╔╝░
░╚═══██╗██╔══██║██╔══╝░░██╔══╝░░██║░░██║░░╚██╔╝░░
██████╔╝██║░░██║███████╗███████╗██████╔╝░░░██║░░░
╚═════╝░╚═╝░░╚═╝╚══════╝╚══════╝╚═════╝░░░░╚═╝░░░

██╗░█████╗░██████╗░░█████╗░  ░█████╗░░██████╗░██████╗██╗██╗░░░██╗████████╗
██║██╔══██╗██╔══██╗██╔══██╗  ██╔══██╗██╔════╝██╔════╝██║██║░░░██║╚══██╔══╝
██║██║░░╚═╝██████╔╝██║░░╚═╝  ███████║╚█████╗░╚█████╗░██║██║░░░██║░░░██║░░░
██║██║░░██╗██╔═══╝░██║░░██╗  ██╔══██║░╚═══██╗░╚═══██╗██║██║░░░██║░░░██║░░░
██║╚█████╔╝██║░░░░░╚█████╔╝  ██║░░██║██████╔╝██████╔╝██║╚██████╔╝░░░██║░░░
╚═╝░╚════╝░╚═╝░░░░░░╚════╝░  ╚═╝░░╚═╝╚═════╝░╚═════╝░╚═╝░╚═════╝░░░░╚═╝░░░
*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<cctype>
#include<climits>
#include<string>
#include<unordered_map>
#define testcase int t; cin>>t; while(t--)
#define pi acos(-1)
#define eps 1e-9
#define fix(n) cout <<fixed<<setprecision(n)
#define line cout << '\n';
#define sz(s)	(int)(s.size())
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define dpp(arr,val) memset(arr,val,sizeof(arr))
#define ull unsigned long long
#define ld long double
#define pq priority_queue
#define mp make_pair
#define S second
#define F first
#define cin(vec)  for(auto& i : (vec)) cin >> i;
#define cout(vec) for(auto& i : (vec)) cout << i << " ";

using namespace std;
typedef long long   ll;

void file()
{
#ifndef ONLINE_JUDGE
    //freopen("take.txt", "r", stdin);
    //freopen("print.txt", "w", stdout);
#else
    freopen("mex.in", "r", stdin);
    //freopen("stand.out", "w", stdout);
#endif
}

void fast()
{
    //ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
}

bool getbit(const int& num, const int& index)
{
    return (1 & (num >> index));
}

ll  gcd(ll  a, ll b)
{
    return (b == 0 ? abs(a) : gcd(b, a % b));
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

void solve()
{
    int n, k;
    cin >> n >> k;
    vector<int>v(n); cin(v);
    ll sum = 0, temp = 0, ans = 0;
    for (int i = 0; i < n; i++) {
        sum += v[i];
        temp = 0;
        for (int j = i; j < n; j+=k) {
            temp += v[i];
        }
        ans = max(ans, temp);
    }
    cout << ans;
    line
}

int main()
{
    fast();
    //file();
    //testcase
        solve();
}
//sort(all(x), [](parameters) {return value});
//V.erase( unique ( V.begin(), V.end() ),  V.end() );
Copy
Offer Saeedy
GNU G++17
1 ms
184 KB
Wrong Answer