-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c96b278
commit 607e3ad
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
codeforces/1000-1200/.cph/.B.SummationGame.cpp_0b67f0a514202e452a1fcd71f794c547.prob
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name":"Local: B","url":"/home/akshat/Documents/C_plus_plus/codeforces/1000-1200/B.SummationGame.cpp","tests":[{"id":1705860310903,"input":"8\n1 1 1\n1\n4 1 1\n3 1 2 4\n6 6 3\n1 4 3 2 5 6\n6 6 1\n3 7 3 3 32 15\n8 5 3\n5 5 3 3 3 2 9 9\n10 6 4\n1 8 2 9 3 3 4 5 3 200\n2 2 1\n4 3\n2 1 2\n1 3\n","output":"0\n2\n0\n3\n-5\n-9\n0\n-1\n"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"/home/akshat/Documents/C_plus_plus/codeforces/1000-1200/B.SummationGame.cpp","group":"local","local":true} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Author: Akshat Khosya | ||
#include <bits/stdc++.h> | ||
#define fast ios_base::sync_with_stdio(0) | ||
#define fs cin.tie(0) | ||
#define ll long long int | ||
#define pb push_back | ||
#define fr(i, n) for (int i = 0; i < n; i++) | ||
#define fm(i, n) for (int i = n - 1; i >= 0; i--) | ||
using namespace std; | ||
void akshat() | ||
{ | ||
int n, k, x; | ||
cin >> n >> k >> x; | ||
vector<int> v(n); | ||
fr(i, n) cin >> v[i]; | ||
sort(v.begin(), v.end(), greater<int>()); | ||
vector<int> prefixSum(n + 1); | ||
prefixSum[0] = 0; | ||
for (int i = 1; i <= n; i++) | ||
{ | ||
prefixSum[i] = prefixSum[i - 1] + v[i - 1]; | ||
} | ||
int sum = INT_MIN; | ||
for (int i = 0; i <= k; i++) | ||
{ | ||
sum = max(sum, prefixSum[n] - 2 * (prefixSum[min(i + x, n)]) + prefixSum[i]); | ||
} | ||
cout << sum << endl; | ||
} | ||
int main() | ||
{ | ||
fast; | ||
fs; | ||
int t; | ||
cin >> t; | ||
while (t--) | ||
{ | ||
akshat(); | ||
} | ||
return 0; | ||
} | ||
/* | ||
1. Bob Want to maximize the sum and alice want to minimize the sum. | ||
2. Alice will make all element negative form highest order. | ||
3. Now sort the array and calculate prefix sum. | ||
4. for every k check for max sum and return it. | ||
*/ |