fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t;
  6. cin>>t;
  7. while(t--)
  8. {
  9. int stations;
  10. cin>>stations;
  11. int travel[stations-1],wait[stations];
  12. for(int i=0;i<stations-1;i++)
  13. cin>>travel[i];
  14. for(int i=1;i<stations-1;i++)
  15. {
  16. cin>>wait[i];
  17. }
  18. int q;
  19. cin>>q;
  20. while(q--)
  21. {
  22. int type,a,b,time=0,wtime=0,minWait=INT_MAX;
  23. cin>>type>>a>>b;
  24. a--;
  25. b--;
  26. if(a>b)
  27. {
  28. int temp=a;
  29. a=b;
  30. b=temp;
  31. }
  32. for(int i=a;i<b;i++)
  33. {
  34. time+=travel[i];
  35. wtime+=travel[i];
  36. }
  37. for(int i=a+1;i<b;i++)
  38. {
  39. time+=wait[i];
  40. if(minWait>wait[i])
  41. minWait=wait[i];
  42. }
  43. if(a!=b)
  44. wtime+=(b-a-1)*minWait;
  45. if(type)
  46. cout<<wtime<<endl;
  47. else
  48. cout<<time<<endl;
  49. }
  50. }
  51. return 0;
  52. }
Success #stdin #stdout 0s 15224KB
stdin
1
6
20 30 40 50 60
2 3 4 5
4
0 2 5
1 2 5
0 6 1
1 6 1
stdout
127
126
214
208