fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int main()
  5. {
  6. long long int t, n, i;
  7. scanf("%lld", &t);
  8. while(t--)
  9. {
  10. scanf("%lld", &n);
  11. long long int d, grass=0;
  12. for(i=1; i<=n; i++)
  13. {
  14. scanf("%lld", &d);
  15. grass+=(d*i);
  16. }
  17. grass=abs(grass);
  18. printf("%lld\n", grass);
  19. }
  20. return 0;
  21. }
  22.  
  23. /*
  24.  
  25. Test1:
  26.  
  27. Input:
  28. 5
  29. 2 -5 -2 -1 6
  30.  
  31. Output:
  32. 16
  33.  
  34. =============================================
  35. Test 2:
  36.  
  37. Input:
  38. 12
  39. -51 -22 56 -9 47 -59 99 -61 0 -191 999 -808
  40.  
  41. Output:
  42. 1286
  43.  
  44. ============================================
  45. Test3:
  46.  
  47. Input:
  48. 9
  49. -15 3 -7 24 -19 17 -5 3 -1
  50.  
  51. Output:
  52. 71
  53.  
  54. =========================================
  55. Test4:
  56.  
  57. Input:
  58. 19
  59. 51 -999 474 -14 -21 -764 41 -42 -64 -99 -444 -616 1111 -63 1201 6666
  60.  
  61. Output:
  62. 17464
  63.  
  64. ====================================================
  65. Test5:
  66.  
  67. Input:
  68. 6
  69. -91555 -45617 75642 -66454 12345 115639
  70.  
  71. Output:
  72. 533880
  73.  
  74. ===================================================
  75. Test6:
  76.  
  77. Input:
  78. 7
  79. 9494 1427 -6479 4976 -12465 6654 -3607
  80.  
  81. Output:
  82. 40929
  83. */
Success #stdin #stdout 0.05s 3344KB
stdin
6
5
2 -5 -2 -1 6
12
-51 -22 56 -9 47 -59 99 -61 0 -191 999 -808
9
-15 3 -7 24 -19 17 -5 3 -1
19
51 -999 474 -14 -21 -764 41 -42 -64 -99 -444 -616 1111 -63 1201 6666 
6
-91555 -45617 75642 -66454 12345 115639
7
9494 1427 -6479 4976 -12465 6654 -3607
stdout
12
494
53
2395540
1562612575
1562104167