-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathKSUM.cpp
More file actions
66 lines (63 loc) · 1.18 KB
/
KSUM.cpp
File metadata and controls
66 lines (63 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <bits/algorithmfwd.h>
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
ll T;
cin>>T;
while(T!=0)
{
ll N=0,K=0;
cin>>N>>K;
vector<long long int> v;
vector<long long int> s;
for(int i=0;i<N;i++)
{ll input=0;
cin>>input;
v.push_back(input);
}
ll p=0;
p=N%K;
ll sum=0;
if(N%K!=0)
{
for(int i=0;i<N-p;i++)
{
sum=sum+v[i];
}
if(p+1<K)
{
sum=sum+v[N-p];
}
if(p+1>=K)
{
while(p!=0)
{
sum=sum+v[N-p];
p--;
if(p+1<K&&p!=0)
{
cout<<sum<<" "<<v[N-p]<<endl;
break;
}
if(p+1<K&&p==0)
{
cout<<sum<<endl;
break;
}
}
}
}
else
{
for(int i=0;i<N;i++)
{
sum=sum+v[i];
}
cout<<sum<<endl;
}
T--;
}
}