right approach since there's a lot of Input in this runtime can be greatly reduced by turning off the syncing with syncing off i got AC in 0.06 with same approach

Active In

Competitive Programming

Algorithms and Computer Programming

International Olympiad in Informatics

Featured Contributions

reply in this discussion

right approach since there's a lot of Input in this runtime can be greatly reduced by turning off the syncing with syncing off i got AC in 0.06 with same approach

Read more… (31 words)

reply in this discussion

Saw some hints of people using Heaps its nod bad but not required if k>n then the solution would for a sorted array the middle element + last element i.e both the arrays are sorted in such fashion that highest value of first array is smaller or equal to lowest of other array or vice versa now since k is limited we have to find a array confifuration that best represents the above to do so wee need to determine whether to move from 1 to 2 array or from 2 to 1 array one way to do so is to check which array closely resembles the required config but since there are only two arrays one can check for both the cases and print the minimum.Overhead of maintaining the original states of array can be reduced by not actually swapping the values.

Here's my solution

#include <iostream>

#include<algorithm>

using namespace std;

int main() {int n,k;

Read more… (218 words)

reply in this discussion

reply in this discussion

A simple solution

#include<iostream>using namespace std;int main(){ios_base::sync_with_stdio(0);cin.tie(NULL);int n,nd=0,ndt=0,mnt=0,prd=0,nm=0,prm=0;cin>>n;int stk[n];int k=0;for(int i=0;i<n;i++){int j;cin>>j;if(j==1){stk[k]=i;++k;++ndt;}if(j==2){--k;mnt=i-stk[k]+1;if(mnt>nm){nm=mnt;prm=stk[k]+1;

Read more… (3 words)