|
| 1 | +#include<bits/stdc++.h> |
| 2 | + |
| 3 | +using namespace std; |
| 4 | + |
| 5 | +#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); |
| 6 | +#define MAX 1000000 |
| 7 | +#define ll long long |
| 8 | +#define db double |
| 9 | +#define str string |
| 10 | +#define pb push_back |
| 11 | +#define For(i,s,e) for (ll i=(s); i<(e); i++) |
| 12 | +#define Forrev(i,s,e) for (ll i=(s); i>=(e); i--) |
| 13 | +#define all(v) v.begin(),v.end() |
| 14 | + |
| 15 | +#define vll vector<ll> |
| 16 | +#define vs vector<string> |
| 17 | +#define mapll map<ll,ll> |
| 18 | +#define pll pair<ll,ll> |
| 19 | +#define initialise(a, x) memset(a, x, sizeof(a)) |
| 20 | +#define maxheap priority_queue<ll> |
| 21 | +#define minheap priority_queue<ll,vector<ll> ,greater<ll>> |
| 22 | + |
| 23 | +#define ff first |
| 24 | +#define ss second |
| 25 | +#define endl "\n" |
| 26 | +#define mp make_pair |
| 27 | +const ll mod=1e9 + 7; |
| 28 | + |
| 29 | +ll takemod(ll a) { |
| 30 | + return ((a%mod)+mod)%mod; |
| 31 | +} |
| 32 | + |
| 33 | +ll gcd(ll a, ll b) { |
| 34 | + if (b == 0) |
| 35 | + return a; |
| 36 | + return gcd(b, a % b); |
| 37 | +} |
| 38 | + |
| 39 | +ll fast_exp(ll base, ll expo) { |
| 40 | + ll res=1; |
| 41 | + while(expo>0) { |
| 42 | + if(expo&1) res=(res*base)%mod; |
| 43 | + base=(base*base)%mod; |
| 44 | + expo>>=1;} |
| 45 | + return res; |
| 46 | +} |
| 47 | + |
| 48 | +ll modinv(ll a) { |
| 49 | + return takemod(fast_exp(takemod(a), mod-2)); |
| 50 | +} |
| 51 | + |
| 52 | + |
| 53 | +signed main() |
| 54 | +{ |
| 55 | + fast_cin(); |
| 56 | + #ifndef ONLINE_JUDGE |
| 57 | + freopen("C:/IO/in.txt", "r", stdin); |
| 58 | + freopen("C:/IO/out.txt", "w", stdout); |
| 59 | + #endif |
| 60 | + ll t,n; |
| 61 | + cin>>t; |
| 62 | + For(l,0,t) |
| 63 | + { |
| 64 | + cin>>n; |
| 65 | + ll arr[n]; |
| 66 | + For(i,0,n) |
| 67 | + { |
| 68 | + cin>>arr[i]; |
| 69 | + } |
| 70 | + |
| 71 | + ll x; |
| 72 | + cin>>x; |
| 73 | + |
| 74 | + ll i=0,j=n-1,sum1=0,sum2=0; |
| 75 | + ll sumarr[n]; |
| 76 | + memset(sumarr,0,sizeof(sumarr)); |
| 77 | + |
| 78 | + ll markarr[n]; |
| 79 | + memset(markarr,-1,sizeof(markarr)); |
| 80 | + |
| 81 | + while(i<=j) |
| 82 | + { |
| 83 | + if(i==j) |
| 84 | + { |
| 85 | + if(markarr[i]!=-1) |
| 86 | + break; |
| 87 | + ll ans1=0,ans2=0; |
| 88 | + For(k,0,n) |
| 89 | + { |
| 90 | + //cout<<markarr[i]<<endl; |
| 91 | + if(markarr[k]==1) |
| 92 | + ans1++; |
| 93 | + else if(markarr[k]==2) |
| 94 | + ans2++; |
| 95 | + } |
| 96 | + //cout<<ans1<<"XX"<<ans2<<endl; |
| 97 | + if(ans1>=ans2) |
| 98 | + { |
| 99 | + markarr[i]=1; |
| 100 | + i++; |
| 101 | + } |
| 102 | + else |
| 103 | + { |
| 104 | + markarr[i]=2; |
| 105 | + j--; |
| 106 | + } |
| 107 | + } |
| 108 | + else |
| 109 | + { |
| 110 | + sum1=0,sum2=0; |
| 111 | + sum2=arr[j]; |
| 112 | + markarr[j]=2; |
| 113 | + while(i<j and sum1<x*sum2) |
| 114 | + { |
| 115 | + if(sum1+arr[i]-sumarr[i]>x*sum2) |
| 116 | + { |
| 117 | + sumarr[i]+=x*sum2-sum1; |
| 118 | + sum1=sum2; |
| 119 | + markarr[i]=1; |
| 120 | + if(sumarr[i]==arr[i]) |
| 121 | + i++; |
| 122 | + break; |
| 123 | + } |
| 124 | + else |
| 125 | + { |
| 126 | + sum1+=arr[i]-sumarr[i]; |
| 127 | + markarr[i]=1; |
| 128 | + i++; |
| 129 | + } |
| 130 | + } |
| 131 | + j--; |
| 132 | + //cout<<i<<" "<<j<<endl; |
| 133 | + |
| 134 | + } |
| 135 | + |
| 136 | + } |
| 137 | + |
| 138 | + ll ans1=0,ans2=0; |
| 139 | + For(k,0,n) |
| 140 | + { |
| 141 | + //cout<<markarr[k]<<" "; |
| 142 | + if(markarr[k]==1) |
| 143 | + ans1++; |
| 144 | + else if(markarr[k]==2) |
| 145 | + ans2++; |
| 146 | + } |
| 147 | + cout<<ans1<<" "<<ans2<<endl; |
| 148 | + } |
| 149 | + |
| 150 | + return 0; |
| 151 | +} |
0 commit comments