Skip to content

Commit 1de25c1

Browse files
committedMay 19, 2023
Added 1832B - Maximum Sum.cpp
1 parent d4d05f6 commit 1de25c1

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
 

‎1832B - Maximum Sum.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// ॐ नमः शिवाय
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
#define ll long long
5+
6+
// Code Written By: Vikash Patel
7+
// Codeforces Profile: https://codeforces.com/profile/vikashpatel
8+
9+
int main()
10+
{
11+
int t;
12+
cin>>t;
13+
while(t--)
14+
{
15+
int n,k;
16+
cin>>n>>k;
17+
int a[n+1];
18+
for(int i=0; i<n ;i++)
19+
{
20+
cin>>a[i];
21+
}
22+
ll maxi = 0;
23+
sort(a, a+n);
24+
ll sum = 0;
25+
ll b[n];
26+
for(int i=0; i<n; i++)
27+
{
28+
sum += a[i];
29+
b[i+1] = b[i]+a[i];
30+
}
31+
for(int i=0; i<=k; i++)
32+
{
33+
maxi = max(maxi, b[n-i]-b[2*(k-i)]);
34+
}
35+
cout<<maxi<<endl;
36+
}
37+
return 0;
38+
}

0 commit comments

Comments
 (0)
Please sign in to comment.