diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2022-07-08 19:54:42 +0200 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2022-07-08 19:54:42 +0200 |
| commit | dd684349c67c988ef19707cb65e637b6906fac75 (patch) | |
| tree | 2fd9ac45ef08351c8164eda640dade2890f4c731 /codechef/MaximumWeightDifference | |
| parent | 4688ed5f3a56ac6698250e2169adbfbe53b8b685 (diff) | |
| download | competitive-programming-dd684349c67c988ef19707cb65e637b6906fac75.tar.xz competitive-programming-dd684349c67c988ef19707cb65e637b6906fac75.zip | |
Solved some new problems
Diffstat (limited to 'codechef/MaximumWeightDifference')
| -rwxr-xr-x | codechef/MaximumWeightDifference/main | bin | 0 -> 44720 bytes | |||
| -rw-r--r-- | codechef/MaximumWeightDifference/main.cpp | 32 | ||||
| -rw-r--r-- | codechef/MaximumWeightDifference/main_input0.txt | 5 | ||||
| -rw-r--r-- | codechef/MaximumWeightDifference/main_output0.txt | 2 |
4 files changed, 39 insertions, 0 deletions
diff --git a/codechef/MaximumWeightDifference/main b/codechef/MaximumWeightDifference/main Binary files differnew file mode 100755 index 0000000..e5ce1f4 --- /dev/null +++ b/codechef/MaximumWeightDifference/main diff --git a/codechef/MaximumWeightDifference/main.cpp b/codechef/MaximumWeightDifference/main.cpp new file mode 100644 index 0000000..751084c --- /dev/null +++ b/codechef/MaximumWeightDifference/main.cpp @@ -0,0 +1,32 @@ +#include <bits/stdc++.h> + +using namespace std; + +int sum(vector<int> &v, int start, int end) { + int sum = 0; + for(int i = start; i < end; i++) { + sum += v[i]; + } + return sum; +} + + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int tt; + cin >> tt; + while (tt--) { + int n, k; + cin >> n >> k; + vector<int> v(n); + for (int &x : v) + cin >> x; + sort(v.begin(), v.end()); + if(n == 1) { + cout << v[0]; + } else { + cout << sum(v, k, v.size()) - sum(v, 0, k) << endl; + } + } +} diff --git a/codechef/MaximumWeightDifference/main_input0.txt b/codechef/MaximumWeightDifference/main_input0.txt new file mode 100644 index 0000000..89c2c4e --- /dev/null +++ b/codechef/MaximumWeightDifference/main_input0.txt @@ -0,0 +1,5 @@ +2 +5 2 +8 4 5 2 10 +8 3 +1 1 1 1 1 1 1 1 diff --git a/codechef/MaximumWeightDifference/main_output0.txt b/codechef/MaximumWeightDifference/main_output0.txt new file mode 100644 index 0000000..f1f71f3 --- /dev/null +++ b/codechef/MaximumWeightDifference/main_output0.txt @@ -0,0 +1,2 @@ +17 +2 |
