1 solutions
-
0
考虑希望最小化所有小组不协调度,最佳方案是排序后每三个人分在一起。
求完每个小组的不协调度之后加和即可。
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { int n; cin >> n; long long ans = 0; for(int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + 1 + n); for(int i = 1; i <= n; i += 3) { ans += a[i + 2] - a[i]; } cout << ans << endl; return 0; }
- 1
Information
- ID
- 18
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 8
- Tags
- (None)
- # Submissions
- 42
- Accepted
- 6
- Uploaded By