fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n, x, b, cnt, a;
  7. b=cnt=0;
  8. scanf("%d%d", &n, &x);
  9. for(int i=0; i<n; i++) {
  10. scanf("%d", &a);
  11. b+=a;
  12. }
  13. while(b!=0) {
  14. if(b>0) {
  15. if(b-x>0) {
  16. cnt++;
  17. b-=x;
  18. }
  19. else {
  20. cnt++;
  21. b=0;
  22. }
  23. }
  24. else {
  25. if(b+x<0) {
  26. cnt++;
  27. b+=x;
  28. }
  29. else {
  30. cnt++;
  31. b=0;
  32. }
  33. }
  34. }
  35. printf("%d\n", cnt);
  36. return 0;
  37. }
Success #stdin #stdout 0s 3300KB
stdin
2 3
-2 -2
stdout
2