1 solutions

  • 8
    @ 2025-7-12 9:23:38
    #include <bits/stdc++.h>
    using namespace std;
    int n, a[105], ans;
    
    int main() {
    	cin >> n;
    	for (int i = 1; i <= n; i++) {
    		cin >> a[i];
    	}
    	sort(a + 1, a + n + 1);
    	for (int i = 1; i <= n; i += 2) {
    		ans += a[i + 1] - a[i];
    	}
    	cout << ans;
    	return 0;
    }
    
  • 1

Information

ID
357
Time
1000ms
Memory
64MiB
Difficulty
1
Tags
# Submissions
44
Accepted
33
Uploaded By