1 solutions

  • 1
    @ 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
    2
    Tags
    # Submissions
    36
    Accepted
    25
    Uploaded By