fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define el << "\n"
  5.  
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. cout.tie(nullptr);
  10.  
  11. int p,d;
  12. cin>>p>>d;
  13. int k[2005];
  14. for (int i = 0;i<d;i++) {
  15. cin>>k[i];
  16. }
  17.  
  18. int plates[2005] = {0};
  19. for (int i =0;i<d;i++) {
  20. for (int j = 0;j<k[i];j++) {
  21. plates[j]++;
  22. }
  23. for (int a=0;a < p - 1;a++) {
  24. for (int b = 0;b<p - a - 1;b++) {
  25. if (plates[b] < plates[b + 1]) {
  26. int x = plates[b];
  27. plates[b] = plates[b + 1];
  28. plates[b + 1] = x;
  29. }
  30. }
  31. }
  32. }
  33. cout << plates[0] el;
  34. return 0;
  35. }
Success #stdin #stdout 0s 5316KB
stdin
10 4
5 3 5 2
stdout
4