Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- const int N = 1e3 + 5;
- const int mod = 1e9 + 7;
- const int INF = 1e18;
- int dp[N][5];
- signed main()
- {
- int n;
- cin >> n;
- vector<int> a(n);
- for(int i = 0; i < n; i++){
- cin >> a[i];
- }
- sort(a.begin() , a.end());
- dp[1][1] = a[1] - a[0];
- dp[1][0] = INF;
- for(int i = 2; i < n; i++){
- dp[i][0] = dp[i - 1][1];
- dp[i][1] = min(dp[i - 1][0] , dp[i - 1][1]) + a[i] - a[i - 1];
- }
- cout << dp[n - 1][1] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement