Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Design and analysis of algorithms / Practicum / Maycamp-198_Mathematics.cpp
diff options
context:
space:
mode:
1 files changed, 34 insertions, 0 deletions
-rw-r--r--Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Mathematics.cpp34
diff --git a/Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Mathematics.cpp b/Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Mathematics.cpp
new file mode 100644
index 0000000..47a846d
--- /dev/null
+++ b/Year 2/Design and analysis of algorithms/Practicum/Maycamp-198_Mathematics.cpp
@@ -0,0 +1,34 @@
+#include <cstdio>
+#include <vector>
+#include <algorithm>
+using namespace std;
+
+
+int main() {
+ int n = 0, l = 0, r = 0;
+ scanf("%d %d %d", &n, &l, &r);
+ vector<short> a;
+ short temp = 0;
+ for (int i = 0; i < n; i++) {
+ scanf("%hd", &temp);
+ a.push_back(temp);
+ }
+ sort(a.begin(), a.end());
+ long long sum = 0;
+ l = n-l;
+ r = n-r;
+ for (int i = 0; i < n; i++) {
+ if (i == l || i == r) {
+ printf("%d ", a[i]);
+ if (l == r)
+ printf("%d ", a[i]);
+ }
+ else if (i > r) {
+ sum -= a[i];
+ }
+ else if (i > l) {
+ sum += a[i];
+ }
+ }
+ printf("%lld", sum);
+}