Advertisement
Ahmed_Negm

Untitled

Sep 29th, 2022
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. #define ll long long
  7. #define ull unsigned long long
  8. #define nl '\n'
  9. #define sz(x) int(x.size())
  10. #define all(x) x.begin(),x.end()
  11. #define rall(s)  s.rbegin(), s.rend()
  12. #define getline(s) getline(cin>>ws,s)
  13. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  14. #define pi  3.141592653589793
  15. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  16. #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
  17.  
  18.  
  19. void Fast_IO(){
  20. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  21. // freopen("filename.in", "r", stdin);
  22. // freopen("filename.txt", "w", stdout);
  23. #ifndef ONLINE_JUDGE
  24. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  25. #endif
  26. }
  27.  
  28. int x[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };
  29. int y[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };
  30.  
  31.  
  32.  
  33.  
  34. void solve(){
  35. ll n; cin>>n;
  36. vector<ll> v(n),ans1(n),ans2(n);
  37. for(int i=0;i<n;i++) cin>>v[i];
  38. ans1[0] = ans2[0] = v[0];
  39. for(int i=1; i<n; i++){
  40.     ans1[i] = v[i] + ans1[i-1];
  41.     ans2[i] = ans2[i-1] - v[i];
  42.     ans2[i] = ans2[i] <0? ans1[i]:ans2[i];
  43. }
  44. if(ans1 != ans2) cout<<"-1";
  45. else for(auto &i:ans1) cout<<i<<" ";
  46. cout<<nl;
  47.  
  48.  
  49. }
  50.  
  51. int main(){
  52.     Fast_IO();
  53. int t =1;
  54. cin>>t;
  55. while(t--){
  56. solve();
  57. }
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement