We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d4d05f6 commit 1de25c1Copy full SHA for 1de25c1
1832B - Maximum Sum.cpp
@@ -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