fork(2) download
  1. #include <bits/stdc++.h>
  2. #define ff first
  3. #define ss second
  4. #define sz size()
  5. #define pb push_back
  6. #define mp make_pair
  7. #define pf push_front
  8. #define ff first
  9. #define ss second
  10. #define SET(a,b) memset(a,b,sizeof(a))
  11. #define all(c) (c).begin(),(c).end()
  12. #define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
  13. #define present(c,x) ((c).find(x) != (c).end())
  14. #define cpresent(c,x) (find(all(c),x) != (c).end())
  15. #define SL(n) scanf("%lld",&n)
  16. #define PL(n) printf("%lld",n)
  17. #define SI(n) scanf("%d",&n)
  18. #define PI(n) printf("%d",n);
  19. #define _ ios_base::sync_with_stdio(0);cin.tie(0)
  20. using namespace std;
  21. typedef long long int LL;
  22. class node{
  23. public:
  24. LL ss;
  25. LL length;
  26. };
  27. typedef vector<LL> VL;
  28. typedef vector<int> VI;
  29. typedef vector<VL> VVL;
  30. typedef pair<LL,LL> PLL;
  31. typedef stack<node> st;
  32. typedef queue<node> qu;
  33. typedef pair<int ,int> II;
  34. typedef vector<II> VII;
  35. void FastIO()
  36. {
  37. ios_base::sync_with_stdio(0);
  38. cin.tie(NULL);
  39. cout.tie(NULL);
  40. }
  41. LL a[100005];
  42. int main()
  43. {
  44. LL n,i,j;
  45. LL t;
  46. cin >> t;
  47. assert(t <= 20);
  48. while(t--){
  49. cin >> n;
  50. assert(n <= 100000);
  51. for(i=0;i<n;i++){
  52. cin >> a[i];
  53. assert(a[i] <= 1000000000);
  54. }
  55. LL ans=0;
  56. bool flag =0;
  57. for(i=0,j=n-1;i<=j;){
  58. if(a[i] == a[j]){
  59. i++ ;
  60. j-- ;
  61. }
  62. else if(a[i] > a[j]){ // need to merge from tail.
  63. j-- ;
  64. a[j] += a[j+1] ;
  65. ans++;
  66. }
  67. else{ // ned to merge from head.
  68. i++ ;
  69. a[i] += a[i-1];
  70. ans++;
  71. }
  72. }
  73. cout << ans << endl;
  74.  
  75. }
  76.  
  77. return 0;
  78. }
Runtime error #stdin #stdout #stderr 0s 4196KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog: prog.cpp:47: int main(): Assertion `t <= 20' failed.