Korotkodul

СПБГУ_H_1

Dec 27th, 2021 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. using namespace std;
  12. using ll = long long;
  13. using ld = long double;
  14. void cv(vector <ll> &v){
  15.     for (auto x: v) cout<<x<<' ';
  16.     cout<<"\n";
  17. }
  18. ll t,n;
  19. vector <ll> a;
  20. vector <ll> pref, max_pref, res,ans;//max_pref - храним индексы максимального префикса
  21.  
  22. ll wrk(){cout<<"\n";
  23.     pref.resize(n);
  24.     max_pref.resize(n);
  25.     res.resize(n);
  26.     ans.resize(n);
  27.     pref[0] = a[0];
  28.     max_pref[0] = max(0, a[0]);
  29.     for (int i = 1; i < n; ++ i){
  30.         pref[i] = pref[i-1] + a[i];
  31.         max_pref[i] = max(pref[i], max_pref[i-1]);
  32.         res[i] =
  33.     }
  34.     cout<<"a\n";cv(a);
  35.     cout<<"pref\n";cv(pref);
  36.     cout<<"max_pref\n"; cv(max_pref);
  37.     cout<<"res\n"; cv(res);
  38.     cout<<"ans\n";cv(ans);
  39.     return ans[n-1];
  40. }
  41.  
  42.  
  43. void go(){
  44.     cin>>n;
  45.     a.resize(n); for (ll &x: a) cin>>x;
  46.     ll r = wrk();
  47.     cout<<r<<'\n';
  48. }
  49.  
  50. int main()
  51. {
  52.     ios::sync_with_stdio(0);
  53.     cin.tie(0);
  54.     cout.tie(0);
  55.     cin>>t;
  56.     for (int i = 0; i < t;++i){
  57.         go();
  58.     }
  59. }
  60.  
Add Comment
Please, Sign In to add comment