### cannor147's blog

By cannor147, 3 years ago,

Authors: MikeMirzayanov and geranazavr555

Authors' solution

Author: MikeMirzayanov

Authors' solution

Authors: MikeMirzayanov, cannor147 and geranazavr555

Authors' solution

Authors: MikeMirzayanov, cannor147 and geranazavr555

Authors' solution

Author: MikeMirzayanov

Authors' solution

Authors: MikeMirzayanov, cannor147 and geranazavr555

Authors' solution

Authors: MikeMirzayanov, cannor147 and geranazavr555

Authors' solution

Authors: MikeMirzayanov, cannor147 and geranazavr555

Authors' solution

Authors: MikeMirzayanov, cannor147 and geranazavr555

Authors' solution

• +53

| Write comment?
 » 3 years ago, # |   +14 very good contest!
 » 3 years ago, # | ← Rev. 2 →   0 How to solve C2 if 't' constraint would have been t<=10^5 (without segment tree and treap) ?
•  » » 3 years ago, # ^ |   0 Use two Priority Queues, in one keep those that pass and in the other those that fail. Before printing the result, you have to fail as students as needed to sum less than M. Then, while the greatest from the pq that passes is greater than the smallest of the pq that fails, swap them. Finally, while you can pass the smallest from the pq that fail for free, do it.My submission during contest: 55775417
•  » » » 3 years ago, # ^ |   0 So you're pushing/popping same element multiple times. How are you sure this will work in the given time constraint? Can you please explain a bit more?
•  » » » 3 years ago, # ^ |   0 I have used a similar method but couldn't get the answer ...What I am is doing deleting removing the greatest from the pq till the sum is less than M and then adding the smallest from the pq that fails until the sum is than M ...Can someone help me know why won't this method work?
•  » » » » 3 years ago, # ^ |   +1 4 14 5 5 10 3 
•  » » » » » 3 years ago, # ^ |   0 Thanks...
•  » » » 3 years ago, # ^ |   +9 I solved this with a similar approach here: 55809687, but I believe this solution also depends on the low t constraint. The amount of elements that can be popped from the priority queue at the end depends on the possible difference in answers between two subsequent indices. With the current constraints, the possible difference between t values of two indices is 99, and since each t value must be at least 1, the difference in answer can be at most 99. If you were to have t go up to m, you could construct a case where you alternate t values between 1 and m. For the cases where t is 1, you only need to remove the t values that are equal to m, and thus the answer is current index / 2. For the cases where t is equal to m, you need to remove all previous values and thus the answer is the current index. Here, the amount of elements popped and pushed is O(n^2) and will not pass.
•  » » » 3 years ago, # ^ |   0 In your code you have written saco.top(); inside the while loop. What is the value of saco.top() when i=0 and you haven't put anything inside it. Can you help explain the code ?
•  » » » » 3 years ago, # ^ |   0 when i=0 then u r correct that there will be nothing in pq but u will never go inside that while as first element will always be less than M. also this is mentioned in problem statement ** It's guaranteed that all values of ti are not greater than M. **
•  » » 3 years ago, # ^ |   0 I used two BIT arrays to find the answer, 55812830$su$ stores the prefix sum,$seen$ stores the sorted idx,
•  » » 3 years ago, # ^ |   0 https://codeforces.com/contest/1185/submission/55759936Top programmers usually have the best solutions. He basically puts the students in a multiset (multiset automatically sorts things in O(logN)) and if the sum is bigger than M, he subtracts the biggest students in the multiset and prints the answer. Just doing this would give TLE so he also deletes students from his multiset if the sum is above M. For example, take this case: 5 100 80 40 40 40 60 first sum is 80, so no need to fail any students, output is 0.second sum is 120, so we need to fail one student, output is 1. Since the sum is now bigger than M, and it will always be bigger than M from now forward, its in our best interest to elements from the multiset until the sum is smaller than M.This solution would I think work regardless of the constraint of $t$
•  » » » 3 years ago, # ^ | ← Rev. 2 →   0 No, I don't think this solution works for large $t$.e.g. N = 20000, t = 10000, M = 10000and the array are1...(repeat 10000 times) 10000... (repeat 10000 times)
•  » » » » 3 years ago, # ^ |   0 Maybe maintain an array that stores the sum after each $i$,and then when sum > M, we use binary search to find the first sum in the array that would get the current sum below M, maybe do $int index = lower__bound(sum_array.begin(),sum_array.end(),current_student)-sum_array.begin()$ ? Because sum-current_student is less than M. And then whatever index we get, we add it to every other result. This seems like a TLE as well tbh, but I'm too lazy to figure out a better solution.
•  » » » » » 3 years ago, # ^ |   0 Can you please explain why this approach gives TLE isn't the complexity n(lgn+ n)
•  » » 3 years ago, # ^ |   0 I have used two Fenwick Trees + Binary Search. It will work for t <= 2e7. Code: 55863688
•  » » » 3 years ago, # ^ |   0 Could u explain ur code a little bit for what purpose are u using Fenwick tree
 » 3 years ago, # |   -11 nice contest!!
 » 3 years ago, # |   +1 Hey can someone help me in F Two Pizzas:In the editorial it has been written: "Then, we should go through all possible masks, that could be reached by two different pizzas.For each such mask we should keep two pizzas with the smallest total cost, which gives us that mask (i. e. their bitwise-or is equal to our current mask)."My question is how to choose two pizzas of min-cost that generate a particular mask without going back to brute-force which would, of course, be a TLE.
•  » » 3 years ago, # ^ |   +3 this solution may help you.
•  » » » 3 years ago, # ^ |   0 Thanks mate
 » 3 years ago, # |   +3 Though G1 was a bit easier than F, it's still a really good contest for div 2. The score distribution is a bit weird since i saw someone who solved 8 problems have a higher rank than someone who solved all.
 » 3 years ago, # |   +7 I solved G2 by using a $O(n^3T^2)$ solution. I think it's incorrect but I can't hack it.Can someone help me hack it?
 » 3 years ago, # |   0 can somebody tell me why my code is incorrect? https://codeforces.com/contest/1185/submission/55763542 it is easy to read
 » 3 years ago, # | ← Rev. 2 →   0 For problem D cant we maintain a difference array after sorting the initial array of pairs . now we traverse the difference array and maintain a count of number of different elements in the difference array . if there is only one element say 1,1,1,1... then we can output first or last index since it is in ap already , if the difference array is something like 2 2 1 1 then we output the first occurrence of the changed difference that is index 3 in the above array if the difference array is something like 1 2 3 .... then -1.is this approach correct ?
•  » » 3 years ago, # ^ |   0 Your second case will fail on test 1 2 4 6 8 Difference array will be 1 2 2 2 and your output will be 2 instead of 1.
•  » » » 3 years ago, # ^ |   0 Could u also explain how u solved Nick an array(CF round 569 Problem B)
•  » » » » 3 years ago, # ^ |   0 yes that was pretty simple one if you convert all elements to non negative integer that is either zero or positives. Now you just need to sort the array and then make elements negative pairwise so that you can get maximum product at the end. If your array length is odd then you don't need to add any condition you just need to leave the last element as it will handle itself the maximum product. For example if your array is -2 -4 -1 0 0 1 2 3 then after converting them to non negatives it becomes 1 3 0 0 0 1 2 3 now after sorting and making the elements pairwise negative you will get 0 0 0 1 1 2 3 3 --> -1 -1 -1 -2 -2 -3 -4 -4 now you can restore your array order by sorting it with index for that you can store it in pair.
•  » » » » » 3 years ago, # ^ |   0 Thank u so much for sharing this approach. My approach was count number of positive and negative elements in array and if both positive and negative elements are even or odd make all elements positive elements negative. Else make all positive elements negative except the last one but it is giving me a wrong answer. Can u explain y my logic is wrong?
•  » » » » » » 3 years ago, # ^ |   +1 Consider the following example array[]={-2 -1 2 1} according to your approach neg_count==2 and pos_count==2 here both are even hence you will perform the operation on all elements and your new array will be [3 0 -3 -2] which leads to zero product which is incorrect.
•  » » 3 years ago, # ^ |   0 Check my submission history :|
 » 3 years ago, # |   0 in solution of problem D, i don't really understand why we need to find the maximum difference between two elements in sequence maxd = max(maxd, a[i + 1].first — a[i].first) and how we to to know if we do that, it will correct ?
•  » » 3 years ago, # ^ |   0 Please, try one else. One of authors added another solution, which wasn't coincidental with editorial. I hope, it will help you.
 » 3 years ago, # |   0 Could someone elaborate more on the $3^9$ bruteforce to get the number of satisfied people for each mask? Or as in this submission: 55810335, Why is making the outer loop as the loop over the bits, and the inner loop as the loop over the masks stops double counting. I don't seem to get what it is trying to achieve with order. Here's the for loop, $B$ is a const int which is equal to $9$ and $cntHappy$ has the number of satisfied people for each mask and at first contains the count of the input masks.  for (int j = 0; j < B; ++j) { for (int msk = 0; msk < (1<
•  » » 3 years ago, # ^ |   0 Can Anyone Please Explain how to solve C2 problem in given time constraints. I am not able to understand the solution.
•  » » » 3 years ago, # ^ |   0 Use greedy approach,let's say u have available A marks out of M (u need to pass a student that have index i so A=M-marks[i] ).u want to fill Max amount of students in A so u check count of student having marks 1 to 100 (which, u are maintaining count). Now greedily fill A, so u will get maximum number of passing students.
 » 3 years ago, # |   0 Can anyone please explain this particular line of code of problem c2 posted by author and please also explain the reason behind this line.k += (d + j — 1) / j;
•  » » 3 years ago, # ^ |   0 I will try to explain it. So, according to the editorial, this line will be run if we have situation, when $s_i + t_i - count_k \cdot k \le M$. And in this situation just $a_i + count_k$ may be not mimimal answer (but we want to output the minimal answer).So we need to free some $s_i$ minutes. We know that $k$ students' durations equal $count_k$. And for the minimal answer we need to add only $\lceil \frac{s_i}{k} \rceil$ to $a_i$. Let me rewrite this line in editorial's naming:$a_i += (s_i + k - 1) / k$Note that in programming `(A + B — 1) / B' is equivalent to $\lceil \frac{A}{B} \rceil$
 » 3 years ago, # |   0 Problem EGetting error on test case 5 : wrong answer actual picture doesn't equal to expected [test case 35]Can anyone help me with that?
•  » » 3 years ago, # ^ |   +3 1 2 caYou are getting wrong answer here.
 » 3 years ago, # |   0 Can anyone explain the two BIT approach in C2?
 » 3 years ago, # |   0 I can't understand G2 editorial ... any help?
 » 2 years ago, # |   0 I can't understand the author's solution code of problem B(Email from Polycarp). Can anyone help me? TIA
•  » » 2 years ago, # ^ | ← Rev. 2 →   0 i think i am late but still... split function's work is to convert a string for e.g. hhelllo to h 2, e 1, l 3, o 1 now if u obtain this equivalent for both strings you can easily check if at each index, the alphabet is same and count for string t >= count of string s for that alphabet
 » 2 years ago, # |   0 D's test cases are weak..some sols are failing at- 61 2 5 8 11 13ANS= -1