Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- typedef tree<int,null_type,less_equal<int>,rb_tree_tag, tree_order_statistics_node_update>oset;
- #define hi cout << "test\n" ;/////
- const int mod = 1e9 +7 ;
- #define sp(x) fixed<<setprecision(x)
- #define ll unsigned long long
- const ll inf = 1e18 ;
- #define FastIO ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
- #ifndef ONLINE_JUDGE
- #define dbg(x) cerr << #x <<" = "; _print(x); cerr << endl;
- #else
- #define dbg(x)
- #endif
- 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;}
- 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;}
- ll gcd(ll a, ll b) { return((b == 0) ? a : gcd(b, a % b)); }
- ll lcm(ll a, ll b) { return (b / gcd(a, b)) * a; }
- int max ( int a , int b ) {if ( a > b ) return a ; return b ;}
- int min ( int a , int b ){ if ( a < b ) return a ; return b ; }
- void _print(auto t) {cerr << t;}
- template <class T, class V> void _print(pair <T, V> p);
- template <class T> void _print(vector <T> v);
- template <class T> void _print(deque <T> v);
- template <class T> void _print(set <T> v);
- template <class T, class V> void _print(map <T, V> v);
- template <class T> void _print(multiset <T> v);
- template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";}
- template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " "; } cerr << "]";}
- template <class T> void _print(deque <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " "; } cerr << "]";}
- template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
- template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
- template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
- template < typename T > void output (const vector<T> & vec ){ for(auto elem : vec) cout<<elem<<" ";cout <<"" ;}
- //--------------------------------------------------------------- -------------------------------------------------------------------
- #define int long long
- int out ( int a , int b ) {
- return ( ( a % mod ) * ( b % mod ) ) % mod ;
- }
- int add ( int a , int b ) {
- return ( ( a % mod ) + ( b % mod ) ) % mod ;
- }
- void solve(){
- int n , k ; cin >> n >> k ;
- vector < int > arr ( n ) ;
- for ( auto &x : arr ) cin >> x ;
- int sum = 0;
- for ( int i = 0 ; i < n ; i++ ) {
- sum = add ( sum , arr[i] ) ;
- }
- int cnt = arr[0] ;
- int max_sub = arr[0] ;
- for ( int i = 1 ; i < n ; i++ ) {
- cnt = max ( arr[i] , add ( cnt , arr[i] ) ) ;
- max_sub = max ( max_sub , cnt ) ;
- }
- if ( max_sub <= 0 ) {
- cout << ( sum + mod ) % mod ;
- return ;
- }
- for ( int i = 0 ; i < k ; i++ ) {
- sum += max_sub ;
- sum %=mod ;
- max_sub *= 2;
- max_sub %=mod ;
- }
- cout << sum ;
- }
- //---------------------------------------------------------------------------------------------------------------------------------
- int32_t main(){
- #ifndef ONLINE_JUDGE
- freopen("error.txt","w",stderr) ;
- #endif
- FastIO ;
- int test = 1;
- int TestCases =1 ;
- if ( TestCases )
- cin>>test;
- while(test--){
- solve();
- if(test>0)
- cout << endl;
- }
- }
Add Comment
Please, Sign In to add comment