I applied binary search on the answer. Here is my code.
Btw, how did you solved the 3rd one? What was your thought process in that?
the jee one
I could not solve the 4th one. how did you solve it? any idea?
Diffrentiate it by hand first. Set min to and max to pi/2. Do binary search, if slope is negative, go ahead, if slope is positive go behind. Then compute the value for f(x)
For “Are these equal”
I checked two things
-
The sum of elements must be a multiple of k
-
The minimum no of operations would be equal to maximum element in array and The maximum operations would be simply sum//k
Then i just checked if minimum is less than or equal to maximum value.
I just checked these two condition for Output
Code
int n,k;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++)
cin >> a[i];
sort(a,a+n);
int sum = accumulate(a,a+n,0);
int maxi=a[n-1];
int temp=sum/k;
if(sum%k==0 && temp>=maxi)
cout << "YES" << endl;
else
cout << "NO" << endl;
Any mathematical proof for your this condition I thought of these but was not having proof to do that?
I mean, think of it as non overlapping increments. I will be honest, i don’t have any mathematical proof as well. It’s just instinct
I understand that first condition is only necessary but not sufficient. During the contest, I was not so sure about the second condition. Can you tell me how can you always construct the answer when both the conditions are satisfied?
ok so getting intuition was only main thing in the contest that’s why I don’t like such adhoc problemsets.
anyways Nice intuition keep it up bro.
To make up the maximum element(max) we need to do at least max operations on a single element which will cause a net increase of max * k in the array.
On that lines I built the solution.
But I can’t prove that : For every larger value of sum greater than max * k and divisible by k
the solution will surely exist.
I submitted without proving 
I can say some random proofs, but I’m not sure and i don’t want to misguide someone. Let’s wait for the editorial, shall we?
Thanks My mind was chocked to think that later condition that answer will exist always if max<=(sum/k) great minded persons submitted this question.
No harm in giving a try.
Please explain why do you think so??
Does this contest have a editorial?
Editorials will be posted soon.