Guest User

Untitled

a guest
Sep 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define MAXN 5050
  4. #define pb push_back
  5. #define INF 10000000
  6.  
  7. using namespace std;
  8.  
  9. typedef pair <int, int> pii;
  10. typedef long long ll;
  11.  
  12. int main() {
  13. ofstream fout ("barn1.out");
  14. ifstream fin ("barn1.in");
  15.  
  16. int m, s, c;
  17. fin >> m >> s >> c;
  18.  
  19. priority_queue <int> fila;
  20. int stalls[MAXN];
  21.  
  22. for(int i = 1; i <= c; i++){
  23. fin >> stalls[i];
  24. }
  25.  
  26. sort(stalls + 1, stalls + c + 1);
  27.  
  28. int anterior = stalls[1] + 1, atual;
  29.  
  30. for(int i = 1; i <= c; i++){
  31. atual = stalls[i];
  32. fila.push(atual - anterior - 1);
  33. anterior = atual;
  34. }
  35.  
  36. int sum = (stalls[c] - stalls[1]) + 1;
  37.  
  38. for(int i = 1; i <= m - 1; i++){
  39. sum -= fila.top();
  40. fila.pop();
  41. }
  42.  
  43. if(m > c) fout << c << endl;
  44. else fout << sum << endl;
  45.  
  46. return 0;
  47. }
Add Comment
Please, Sign In to add comment