Use this code to find the value of j . It'll be quite easy .... for( ...){ j = findLeastPossible(0, i, i, a); .... } ll findLeastPossible(int L, int R, int cur, ll *a) { ll ans = INT_MIN; while (L = cur - mid + 1) { ans = mid; R = mid - 1; } else { L = mid + 1; } } return ans; }
Your approach was pretty good however i found this solution on codeforces too and i wanna know how this is working #include using namespace std; typedef long long ll; #define pb push_back #define rep(i, a, b) for (ll i = a; i < b; i++) #define eq(i, a, b) for (ll i = a; i > n; vec arr(n); rep(j, 0, n) { cin >> arr[j]; } queue q; rep(j,0,n) { q.push(arr[j]); while (q.front()
Given array is already sorted ( as given in question) , so elements on right are bigger than elements on left in any sequence. To make score max possible , if you want to include an element , it will increase sequence length by 1 , thus d' = d*Length d' is new denominator and d is old denominator. (This is how factorial works n! = n*(n-1)!) This element multiplied in numerator must be >= length after including it, otherwise answer will decrease which we don't want. As array is sorted, leftmost element will be smallest one , thus we can check if its smaller than total length of current sequence , and if it's decrease length by removing it.
Code :
#include
using namespace std;
#define ll long long
ll bs(ll l, ll h, ll a[], ll i)
{
if(l=(i-m+1)){
if(m==l){
return m;
}else{
if(a[m-1]>=(i-(m-1)+1)){
return bs(l, m-1, a, i);
}else{
return m;
}
}
}else{
bs(m+1, h, a, i);
}
}else{
return -1;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t, n, i, j;
cin>>t;
for(;t--;)
{
cin>>n;
ll a[n], ans[n];
for(i=0; i>a[i];
}
ans[0]=1;
for(i=1; i
very good explainations , Thanks buddy
good explaination
Congrats for becoming Expert again
Thank You 😊
Id?
Very clear and concise explanation sir!
can you make video on codechef starter 80 problem name- "Three People Contest"
Use this code to find the value of j . It'll be quite easy ....
for( ...){
j = findLeastPossible(0, i, i, a);
....
}
ll findLeastPossible(int L, int R, int cur, ll *a)
{
ll ans = INT_MIN;
while (L = cur - mid + 1)
{
ans = mid;
R = mid - 1;
}
else
{
L = mid + 1;
}
}
return ans;
}
🛐
Sir aapki videos kyu nhi aari hai ??? from past 3 weeks
Where is the code ? I'm having trouble implementing the code
Check out the pinned comment !
@@codingcommunitynewtonschoo8582 thnx
Your approach was pretty good however i found this solution on codeforces too and i wanna know how this is working
#include
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define eq(i, a, b) for (ll i = a; i > n;
vec arr(n);
rep(j, 0, n)
{
cin >> arr[j];
}
queue q;
rep(j,0,n)
{
q.push(arr[j]);
while (q.front()
Given array is already sorted ( as given in question) , so elements on right are bigger than elements on left in any sequence. To make score max possible , if you want to include an element , it will increase sequence length by 1 , thus d' = d*Length
d' is new denominator and d is old denominator. (This is how factorial works n! = n*(n-1)!)
This element multiplied in numerator must be >= length after including it, otherwise answer will decrease which we don't want.
As array is sorted, leftmost element will be smallest one , thus we can check if its smaller than total length of current sequence , and if it's decrease length by removing it.
@@ADITYAKUMAR-tb4gm GOT IT , THANKS!