fork(1) download
  1. #include <cstdio>
  2. main() {
  3. int t;scanf("%d",&t);
  4. while (t--) {
  5. int n,m;scanf("%d%d",&n,&m);
  6. int a[n],i,l,p;
  7. long long sum = 0;
  8. for (i = 0; i < n; i++) {
  9. scanf("%d",&a[i]);
  10. sum = sum + a[i];
  11. }
  12. l = sum / n;
  13. p = sum % n;
  14. for (i = 0; i < n; i++) {
  15. if (a[i] < l) {
  16. a[i] = l - a[i];
  17. k = k - a[i];
  18. }
  19. }
  20. std::sort(a,a+n);
  21. for (i = 0; p != 0; i++) {
  22. a[i] = a[i] + 1;
  23. p--;
  24. }
  25. std::sort(a,a+n);
  26. printf("%d\n",a[0]);
  27. }
  28. return 0;
  29. }
  30.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
1
5 4
1 2 3 4 5
compilation info
prog.cpp:2:6: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
 main() {
      ^
prog.cpp: In function ‘int main()’:
prog.cpp:17:33: error: ‘k’ was not declared in this scope
                                 k = k - a[i];
                                 ^
prog.cpp:20:17: error: ‘sort’ is not a member of ‘std’
                 std::sort(a,a+n);
                 ^
prog.cpp:25:17: error: ‘sort’ is not a member of ‘std’
                 std::sort(a,a+n);
                 ^
stdout
Standard output is empty