Created
April 14, 2023 08:03
-
-
Save gvnee/2aadfd9df4dff062dd1bb31b01613b27 to your computer and use it in GitHub Desktop.
best solution for USACO Barn repair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
ID: ------- | |
PROG: barn1 | |
LANG: C++ | |
*/ | |
#include<bits/stdc++.h> | |
using namespace std; | |
typedef long long ll; | |
#define pb push_back | |
ifstream fin ("barn1.in"); | |
ofstream fout ("barn1.out"); | |
int main(){ | |
int m, s, c; | |
fin>>m>>s>>c; | |
if(m>c) m = c; | |
int arr[c]; | |
for(int i = 0;i<c;i++) | |
fin>>arr[i]; | |
sort(arr, arr+c); | |
vector<int> gap; | |
for(int i = 1;i<c;i++) | |
gap.pb(arr[i] - arr[i-1]); | |
sort(gap.begin(), gap.end()); | |
ll res = 0; | |
for(int i = 0;i<=c-1-m;i++) | |
res+=gap[i]; | |
fout<<res + m<<"\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment