1.3.2Barn Repair

  
    
  1. /*
  2. ID: awsd1231
  3. PROG: barn1
  4. LANG: C++
  5. */
  6. #include<iostream>
  7. #include<cstdio>
  8. #include<algorithm>
  9. using namespace std;
  10. int M, S, C, inC[300] = {0}, diffC[300] = {0};
  11. int main() {
  12. freopen("barn1.in", "r", stdin);
  13. freopen("barn1.out", "w", stdout);
  14. cin >> M >> S >> C;
  15. for(int i = 0; i != C; ++i)
  16. cin >> inC[i];
  17. sort(inC, inC + C);
  18. for(int i = 0; i != C-1; ++i) {
  19. diffC[i] = inC[i+1] - inC[i];
  20. }
  21. sort(diffC, diffC + C-1);
  22. int sum = 0;
  23. int piece = M <= C-1 ? M-1 : C-1;
  24. for(int i = 0; i != piece; ++i) {
  25. sum += diffC[C-i-2] - 1;
  26. }
  27. sum += inC[0] - 1 + S - inC[C-1];
  28. sum = S - sum;
  29. cout << sum << endl;
  30. return 0;
  31. }





你可能感兴趣的:(AIR)