Solution - 1733A. Consecutive Sum
- Get link
- X
- Other Apps
Solution - 1733A. Consecutive Sum
A. Consecutive Sum
You are given an array
- Choose two indices
i andj , in whichimodk=jmodk (1≤i<j≤n ). - Swap
ai andaj .
After performing all operations, you have to select
Here
The first line contains one integer
Each test case consists of two lines.
The first line of each test case contains two integers
The second line of each test case contains
For each test case, print the maximum score you can get, one per line.
53 25 6 01 175 37 0 4 0 44 22 7 3 43 31000000000 1000000000 999999997
11
7
15
10
2999999997
In the first test case, we can get a score of
In the third test case, we can get a score of
#include<bits/stdc++.h>#define endl '\n'using namespace std;long long k, n, s, t, x, a[100005];int main(){ios::sync_with_stdio(0);cin.tie(0);for(cin >> t; t--;){cin >> n >> k;for(int i = 1; i <= n; i++){cin >> x;a[i % k] = max(a[i % k], x);}s = 0;for(int i = 0; i < k; i++)s += a[i];cout << s << endl;fill(a, a + k, 0);}}
- Get link
- X
- Other Apps
Comments
Post a Comment