Guest User

Untitled

a guest
Mar 22nd, 2024
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.65 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. using namespace std;
  4. using namespace __gnu_pbds;
  5. typedef tree<int,null_type,less_equal<int>,rb_tree_tag, tree_order_statistics_node_update>oset;
  6. #define hi cout << "test\n" ;/////
  7. const int mod = 1e9 +7 ;
  8. #define sp(x) fixed<<setprecision(x)
  9. #define  ll unsigned long long
  10. const ll inf = 1e18 ;
  11. #define FastIO ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
  12. #ifndef ONLINE_JUDGE
  13. #define dbg(x) cerr << #x <<" = "; _print(x); cerr << endl;
  14. #else
  15. #define dbg(x)
  16. #endif
  17. ll binpow(ll a, ll b) {if (b == 0)return 1; ll res = binpow(a, b / 2);if (b % 2) return res * res * a;else return res * res;}
  18. ll expo(ll a, ll b, ll mod) {ll ans = 1; while (b > 0) {if (b & 1)ans = (ans * a) % mod; a = (a * a) % mod; b = b >> 1;} return ans;}
  19. ll gcd(ll a, ll b) { return((b == 0) ? a : gcd(b, a % b)); }
  20. ll lcm(ll a, ll b) { return (b / gcd(a, b)) * a; }
  21. int max ( int a , int b ) {if ( a > b ) return a ; return b ;}
  22. int min ( int a , int b ){ if ( a < b )  return a ; return b ; }
  23. void _print(auto t) {cerr << t;}
  24. template <class T, class V> void _print(pair <T, V> p);
  25. template <class T> void _print(vector <T> v);
  26. template <class T> void _print(deque <T> v);
  27. template <class T> void _print(set <T> v);
  28. template <class T, class V> void _print(map <T, V> v);
  29. template <class T> void _print(multiset <T> v);
  30. template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";}
  31. template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " "; } cerr << "]";}
  32. template <class T> void _print(deque <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " "; } cerr << "]";}
  33. template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
  34. template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
  35. template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
  36. template < typename T > void output (const vector<T> & vec ){  for(auto elem : vec) cout<<elem<<" ";cout <<"" ;}
  37. //--------------------------------------------------------------- -------------------------------------------------------------------
  38. #define int long long
  39. int out ( int a , int b ) {
  40.        return ( ( a  % mod ) * ( b % mod ) ) % mod ;
  41. }
  42. int add ( int a , int b ) {
  43.    return ( ( a % mod ) + ( b % mod ) ) % mod ;    
  44. }
  45. void solve(){
  46.  
  47.      int n , k ; cin >> n >> k ;
  48.      vector < int > arr ( n ) ;
  49.      for ( auto &x : arr ) cin >> x ;
  50.      
  51.      int sum = 0;
  52.      
  53.      for ( int i = 0 ; i < n ; i++ ) {
  54.         sum = add ( sum , arr[i] ) ;
  55.      }
  56.  
  57.      int cnt = arr[0] ;
  58.      int max_sub = arr[0] ;
  59.  
  60.      for ( int i = 1 ; i < n ; i++ ) {
  61.          cnt = max ( arr[i] , add ( cnt , arr[i] ) ) ;
  62.          max_sub = max ( max_sub , cnt ) ;
  63.      }
  64.  
  65.      if ( max_sub <= 0 ) {
  66.         cout << ( sum + mod ) % mod ;
  67.         return ;
  68.      }
  69.  
  70.  
  71.      for ( int i = 0 ; i < k ; i++ ) {
  72.         sum += max_sub ;
  73.         sum %=mod ;
  74.  
  75.         max_sub *= 2;
  76.         max_sub %=mod ;
  77.      }
  78.      cout << sum ;
  79.  
  80.  
  81. }
  82. //---------------------------------------------------------------------------------------------------------------------------------
  83. int32_t main(){
  84.  #ifndef ONLINE_JUDGE
  85.     freopen("error.txt","w",stderr) ;
  86.  #endif
  87.  
  88.      FastIO ;
  89.      int test = 1;
  90.      int TestCases =1  ;
  91.  
  92.      if ( TestCases )
  93.              cin>>test;
  94.  
  95.      while(test--){
  96.      solve();
  97.       if(test>0)
  98.         cout << endl;
  99.      }
  100.  
  101.  }      
Add Comment
Please, Sign In to add comment