Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Design and analysis of algorithms / Practicum / Maycamp-198_Mathematics.cpp
blob: 47a846db3ad5ace94ae7d805266f6524b9f8835b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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);
}