fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <cstdio>
  5. using namespace std;
  6.  
  7. int main() {
  8. int t;
  9. scanf("%d",&t);
  10. while (t--) {
  11. int n,x;
  12. scanf("%d%d",&n,&x);
  13. vector <int> a(n);
  14. for (int i = 0; i < n; i++) {
  15. scanf("%d",&a[i]);
  16. }
  17. if (n == 1)
  18. printf("%d\n",a[0]+x);
  19. else {
  20. sort(a.begin(),a.end());
  21. int b[n];
  22. for (int i = 1; i < n; i++) {
  23. b[i] = a[i]-a[i-1];
  24. }
  25. int ans = a[0];
  26. int ctr = 1;
  27. for (int i = 1; i < n; i++) {
  28. if (x == 0)
  29. break;
  30. if (x >= ctr *b[i]) {
  31. ans += b[i];
  32. x = x-b[i];
  33. ctr++;
  34. }
  35. else {
  36. ans += x/ctr;
  37. x = 0;
  38. }
  39. }
  40. ans += x/n;
  41. printf("%d\n",ans);
  42. }}
  43. return 0;
  44. }
Success #stdin #stdout 0s 3484KB
stdin
2

3 2

1 5 6

5 5

4 4 4 4 4
stdout
3
5