Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

### vovuh's blog

By vovuh, history, 12 days ago, translation, ,

<almost-copy-pasted-part>

Hello! Codeforces Round #653 (Div. 3) will start at Jun/28/2020 17:35 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participants of the third division, you must:

• take part in at least two rated rounds (and solve at least one problem in each of them),
• do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Daria ZeroAmbition Stepanova, Mikhail pikmike Piklyaev, Maksim Ne0n25 Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round. Also thanks to Artem Rox Plotkin and Dmitrii _overrated_ Umnov for the discussion of ideas and testing the round!

Good luck!

</almost-copy-pasted-part>

UPD: Also thanks to ma_da_fa_ka for testing the round and special thanks to Dmitrii _overrated_ Umnov, Artem Rox Plotkin and, of course, Mike MikeMirzayanov Mirzayanov for discussing ideas and great help with round preparaion!

UPD2: Editorial is published!

• +447

 » 12 days ago, # |   +26 Vovuh orz!
 » 12 days ago, # |   +40 This is missing from the announcement after everyone thought our man vovuh retired...You know I'm back like I never left (I never left)Another sprint, another step (another step)Another day, another breath (another breath)Been chasing dreams, but I never slept (I never slept)
•  » » 10 days ago, # ^ |   0 Get some sleep dude
 » 12 days ago, # |   +185 This has been happening in the last couple of months :)
 » 12 days ago, # |   0 vovuh is back baby!!!!
 » 12 days ago, # | ← Rev. 2 →   -7 At last vovuh come back in div-3 with his interesting problem-set. We missed him 2 continuous div-3 contest. #650(He was not there) And #644(Just in the tester list). Edit: Ok. Only vovuh fans missed him And I am one of them.
•  » » 11 days ago, # ^ |   +6 Would love to know what vovuh feels after reading such cringey comments/memes.
•  » » » 11 days ago, # ^ |   -6 I also want to know, but i think i have not enough ability to get attention of him. Cause he has so many fans like me.
 » 12 days ago, # |   -11 vovuh — Is not just a name, it is an emotion
 » 12 days ago, # |   -8 Missed you Vovuh ❤❤
 » 12 days ago, # |   0 div3 by vovuh are best
 » 12 days ago, # |   +49 vovuh again!
•  » » 10 days ago, # ^ |   0 what if i asked who is this vovuh and why is he referred here ..so many times
•  » » » 10 days ago, # ^ |   0 This is beyond your understanding
 » 11 days ago, # |   0 I am not able to register for the contest. When I click on the CONTESTS options above, I am able to see only ICPC challenge 2020 registration option.
•  » » 11 days ago, # ^ |   0 Go to this Link or wait for ending ICPC Challenge 2020 then can easily register from contest option..
 » 11 days ago, # |   0 I don't see any difference between vovuh problems/non-vovuh problems.
•  » » 11 days ago, # ^ |   +7 Its because you have not participated in any contests and had less than 10 submissions....How will you differentiate then???
•  » » » 11 days ago, # ^ |   +1 i have participated but even i don't see any reasonable difference.
•  » » 10 days ago, # ^ |   +5 I cannot believe what you said.
 » 11 days ago, # |   +9 No one: Literally No One: Not even a single Soul: Not even codeforces: VOVUH fans: "Vovuh orz!!!!!!!!!!!! vovuh is back baby!!!!! Missed you Vovuh ❤❤"
•  » » 11 days ago, # ^ |   +38 Nobody: Somebody: -- "Nobody":
 » 11 days ago, # |   +137 Vovuh orz!!!!!!!!!! vovuh is back baby!!!! Missed you Vovuh ❤❤
•  » » 11 days ago, # ^ |   +145 Spoiler
•  » » 11 days ago, # ^ | ← Rev. 2 →   +10 copy paste from here
•  » » » 11 days ago, # ^ |   +118 I think it's notorious coincidence
•  » » » 11 days ago, # ^ |   0 Cause both of you copied those From above 3 comments.
 » 11 days ago, # |   +17 Starting RN I'm gonna explain my family members to keep quiet during 8:00 — 10:00 Tomorrow ! Maybe they'll understand this time
•  » » 11 days ago, # ^ |   +3 Mine will probably start bugging me on purpose if I say that.
 » 11 days ago, # |   -19 Vovuh : "The man the myth the legend !"
 » 11 days ago, # |   -20 Div-3 and vovuh perfect combination.
 » 11 days ago, # |   -25 Finally vovuh is back :)
•  » » 11 days ago, # ^ |   +12 Try some new idea :))
•  » » » 11 days ago, # ^ |   0 Like
 » 11 days ago, # |   -27
 » 11 days ago, # |   -8
 » 11 days ago, # | ← Rev. 2 →   -28 This comment has been deleted due to negative feedback!
•  » » 11 days ago, # ^ | ← Rev. 2 →   -11 ....
 » 11 days ago, # |   0 I don't know about this man vovuh but going through these comments makes me feel there's a good contest ahead ! Wishing it's true ... All the best to all participants
•  » » 10 days ago, # ^ |   0 So, was it true?
•  » » » 10 days ago, # ^ |   +3 I was stuck at E and I feel Yes is the answer from me
 » 11 days ago, # |   +14 meanwhile vovuh counting all the money he made setting div 3 contests!
 » 11 days ago, # | ← Rev. 3 →   0 MikeMirzayanov No more Div.4 rounds?
•  » » 10 days ago, # ^ |   +9
 » 11 days ago, # |   0 I can nearly always solve div2 C but I can't solve div3 D should div3 D be harder than div2 C ?
•  » » 11 days ago, # ^ |   +2 Stupid comparison
•  » » » 10 days ago, # ^ |   +1 I compare div4B and div1B. It's not stupid.
•  » » » » 10 days ago, # ^ |   -27 u r stupid
•  » » » » » 10 days ago, # ^ |   +9 Mind the color gap
•  » » » » » » 10 days ago, # ^ |   -24 I will be orange soon!!! and this stupid community will upvote me for my shittiest comment these greys and greens used to cry and downvote instead of solving problems!!
•  » » » » » » » 10 days ago, # ^ |   +16 no u won't
•  » » » » » » » » 10 days ago, # ^ |   -6 :) ok
•  » » » » » » » 10 days ago, # ^ |   +5 You surely will.. Apes together ... Strong.
•  » » » 10 days ago, # ^ |   0 why it's stupid div1 A is div2 C so div3 D shouldn't be harder than div2 C but I guess it is
•  » » 10 days ago, # ^ |   0 What's your feeling today can solved not only D also E1 .
•  » » » 10 days ago, # ^ |   0 I didn't solve div 3 D since like a year this time it's easier maybe
 » 10 days ago, # |   +1 Does Div-4 contests are discontinued?
 » 10 days ago, # |   0 vovuh The king!
 » 10 days ago, # |   +16 Cringe overloaded
 » 10 days ago, # | ← Rev. 2 →   +138
•  » » 10 days ago, # ^ |   +5 "It wasn't important"
 » 10 days ago, # |   0 pls can someone tell me what happens in hacks ?
•  » » 10 days ago, # ^ |   0
•  » » 10 days ago, # ^ |   0 Div-3/educational round Hack phase : suppose think. A test can fail a problem .But that was not in the pretest system case.So that problem showed accepted..Then anyone can hack that problem by that case in the 12 hours hacking phase.And the defender no of solved problem-=1. But hacker did not get any point.
•  » » » 10 days ago, # ^ |   0 wait, doesn't the hacker also get 100 points or something?
•  » » » » 10 days ago, # ^ |   +5 In div3 and educational no but in div2,div1,global yes
•  » » » » 10 days ago, # ^ |   0 not in div 3
•  » » 10 days ago, # ^ |   0 Once the contest ends you can see anyone's solution and if you think that in certain test cases this would fail then you can run against it and it is called hacks. If it was successful you get 50 points(depends on round) and if it wasn't you lose certain points and before hack you have to lock your solution.
 » 10 days ago, # |   +5 I know here is not a good place to ask this question but what happened for div4 contests ?? are they removed from codeforces contests or we can see them back soon ??
•  » » 10 days ago, # ^ | ← Rev. 2 →   +8 as I know you are a candidate (maybe I am wrong)I think you don't need Div. 4 contests :|
•  » » 10 days ago, # ^ |   +12
 » 10 days ago, # | ← Rev. 2 →   0 For how much time this server is openThis is my first contest
 » 10 days ago, # |   +18 It is high time to introduce filters to comments section on codeforces -_-.
 » 10 days ago, # |   0 Good Luck.
 » 10 days ago, # |   -15 Harder than usual div 3 :)
•  » » 10 days ago, # ^ |   -26 In my opinion no. A-E1 obvious, E2, F — impossible.
•  » » » 10 days ago, # ^ |   +4 Why do you have Wrong Submissions on obvious questions?Jokes aside, obviously, if you know a concept or saw some observation, it is easy for you. Don't discourage others.
•  » » » » 10 days ago, # ^ |   -45 lol you are grey... there is no problem that obvious for you
•  » » » » » 10 days ago, # ^ |   +17 And I didn't claim any problem is either?
•  » » » 10 days ago, # ^ |   0 why u guys friending my alt acc for div3/div4 rounds?
 » 10 days ago, # |   +12 The gap between E1 and E2??
 » 10 days ago, # |   -18 subho_01santra I think you are expecting a blog from me. I will do it for you, with proof. Gotcha ;)
 » 10 days ago, # |   -15 How would you prepare for the interviews or FAANG if you have just 1 month left keeping in mind you have decent knowledge and grasp over DS Algo and have done more than 100+ questions on leetcode ?Any help would be much appreciated! Thank you :)
 » 10 days ago, # |   0 Help me with D after the contest...
•  » » 10 days ago, # ^ | ← Rev. 2 →   0 D problem was giving TLE when i used unordered_map and when i changed it to map it got accepted. You just have to calculate the minimum number which we have to add to the numbers of the array after which they are divisible by k.This can be calculated by taking mod.for example the numbers are 5,1,3,4 and value of k = 3so for the first element we need to add 1 to get the divisible numberthis number can be calculated by taking mod of a[i]-k & k. -> (k + (a[i]-k)%k)%k;now similarly for other numbers also we'll calculate in the same way so -> 1,2,0,2 is the required array.Now Notice that at a time we can select only one element from the above calculated array. It means that when we see 2 or more elements of same type we can't give the same x to them.It means we have to calculate the next greater number which must be added so that the given number is divisible by k. the next number can be calculated by multiplying k with the number of times this number has previously occurred, which means we have to maintain the hash table for it. Your code here... long long int n,k;cin>>n>>k; long long int a[n],maxm=-1; for(int i=0;imp; vectorrem; for(int i=0;i
•  » » » 10 days ago, # ^ |   0 Nice, Thank you.
•  » » » 10 days ago, # ^ | ← Rev. 2 →   0 D problem was giving TLE when i used unordered_map and when i changed it to map it got accepted. Wow, just tried this and confirm the TLE with unordered_map. Does anyone know why this happens?
•  » » » » 10 days ago, # ^ |   +3 unordered_map worst case is linear, so you can assume that your algorithm time complexity is O(n * n) in some casesdon't use unordered_map when it's not needed and you can solve the problem with map :)
•  » » » » 10 days ago, # ^ |   0 same happened with me in problem D
•  » » » 10 days ago, # ^ |   0 You have not initialized the map but used, does it automatically return zero or I am missing something?
•  » » 10 days ago, # ^ |   0 My approach:for all the array elements calculate the value required to make it a number divisible by k and store it in map and keep incrementing its value if it repeats.Then, find the max "value" in the key-value pair and ans= key+(value-1)*k+1. If two keys have the max value, take the max key.eg: second example, 5 repeats 3 times. so ans= 5+(3-1)*6+1=18.
•  » » » 10 days ago, # ^ |   0 Can you explain why this works ?
•  » » » » 10 days ago, # ^ |   0 To make a such that a%k==0 you have to increase a by k-(a%k). Now if there is another element with the value of a , minimum increment to make a%k==0 is k-(a%k). But according to statement we can not choose multiple indices to increment by same x. So the next minimum value is k-(a%k)+k. If there is another element with the value of a then we have to increment it by k-(a%k)+k+k. So generally,required minimum increment for a value 'a' = k-(a%k) + (frequency of a - 1)*k Maximum of these value for each distinct element is the optimal answer. (As values of other element are less than the answer we can increment them accordingly on the way to the answer )
•  » » » » » 10 days ago, # ^ |   0 thanks ...well explained
•  » » » » » 9 days ago, # ^ |   0 I think your this approach might not work.Consider the case 2 6 3 9 for 3 the minimum required increment = 3 for 9 the minimum required increment = 3And max of (3, 3) will give 3.But the answer here would be 9
•  » » » » » » 9 days ago, # ^ |   0 Yes. I'm sorry i forgot to mention a really important thing. when calculating the frequency of each element we must take the mod of them. Because as in your case the increment needed for both 3 and 9 is 3. As we are focusing mainly on the x (increment) 3 and 9 is same for us. (3%6 = 9%6 = 3).Then the answer would be,6 - 3 + (2 - 1) * 6 = 9
•  » » » 10 days ago, # ^ | ← Rev. 2 →   0 I did the same but I got wa!
•  » » » » 9 days ago, # ^ |   0 Kindly see the above reply you will get the test case where your approach might be failing
•  » » 10 days ago, # ^ |   0 https://codeforces.com/contest/1374/submission/85372487Isn't this linear ... why it's giving TLE?
•  » » » 10 days ago, # ^ |   0 Use map instead and then try your luck
•  » » » » 10 days ago, # ^ |   0 Can you please tell me the logic behind this?My code gave TLE when I used unordered_map but got accepted when I used map.
•  » » » » » 10 days ago, # ^ |   0 Because worst case time complexity for unordered map is in order of n.
•  » » » » » » 10 days ago, # ^ |   0 I am confused about where to use map and where to use unordered_map
•  » » » » » » » 10 days ago, # ^ |   +5 Always use map, never use unordered_map.
•  » » » » » » » » 10 days ago, # ^ |   +4 Or if you wish to use unordered_map, you can try this custom hash
 » 10 days ago, # |   +106
•  » » 10 days ago, # ^ |   +22 I think these would easily be div2 E/F.
•  » » 10 days ago, # ^ |   +1
 » 10 days ago, # |   0 Now I see why vovuh rounds are so amazing. Thoroughly enjoyed the round!
•  » » 10 days ago, # ^ |   +12 What Exactly you find amazing in them??
 » 10 days ago, # |   +76 Easy solution to E2: Copy a solution to this problem https://codeforces.com/contest/799/problem/E which is the exact same except you don't have to reconstruct the indices. Then add boring code to reconstruct the indices
•  » » 10 days ago, # ^ |   +77 nice, 2500 problem for div3 contestants
•  » » 10 days ago, # ^ |   +10 I tried that but I was failing at test 12. Well if this worked for you then I definitely made some really stupid mistake.
 » 10 days ago, # |   0 https://ideone.com/oNqhojMy code is obviously wrong (fails sample test case 2 lol).. But I spent more then an hour can't find where my logic is wrong :/.. I'm almost convinced my 24 IS the correct answer haha..Any help is appreciated. (Would be awesome if you don't spoil the problem but hint me where I went wrong)
•  » » 10 days ago, # ^ | ← Rev. 2 →   +1 Try this test case 1 5 38 15 29 7 15 7 Edit: answer should be 70. Your code gives 108.
•  » » » 10 days ago, # ^ |   0 Ty! I finally was able to get rid of WA but then I was struck by TLE :(https://codeforces.com/contest/1374/submission/85394497Could you identify my bottleneck ? I think the solution is nlog(n) and should pass ..?
•  » » » » 10 days ago, # ^ |   +1 Your code has worst case complexity of O(n^2), having worst case when all elements are same. See this part in your code for(int i = 0; i < n; i++) { if(arr[i] == 0) continue; while(myset.find(arr[i]) != myset.end()) arr[i] += k; myset.insert(arr[i]); } For each iteration of inner loop, it will search multiset the number of times value of arr[i] has appeared before in the array. if n same elements have appeared before, then inner loop runs n times, giving complexity of O(n) for inner loop. The outer loop runs n times, giving total complexity of O(n^2).
 » 10 days ago, # |   +8 Hints for F?
•  » » 10 days ago, # ^ |   +4 Just simulate. If it does not end in correct ordering, then do one triple swap including two same elements from a[]. The simulate again. If still not correct ordering it is impossible.
•  » » » 10 days ago, # ^ |   +5 Thanks for the solution! I thought of this solution, but I am still figuring how to prove that it will be impossible, in case both simulations fail.
•  » » » » 10 days ago, # ^ |   0 Seems that it does not work good :/Here is the submission of #1 85347474 He does count invariants, and if odd parity, does one swap in two same elements.Then sorts with triple swaps, but including the indices in comparison, which does not change the order of elements, but makes the parity even.
•  » » » » 10 days ago, # ^ | ← Rev. 3 →   +10 The idea behind proving whether it is possible/impossible is based on the following idea:Define f(P) for some permutation P to be the number of pairs of indices (i, j) such that i and j are the 'wrong way round' — that is, i < j but in the permutation p, j is to the left of i.For example if n = 4 and P = {1, 2, 3, 4} then f(P) = 0. f({2, 1, 3, 4}) = 1 and f({4, 3, 2, 1}) = 6 (everything is the wrong way round).We claim that each cyclic shift is invariant mod 2 for f(P) — that is, f(P) will change by -2, 0 or 2 with each shift. This is because if [a, b, c] --> [c, a, b] then the pairs (a, c) and (b, c) have reversed (now a, b are to the right of c when before they were to the left). So since there are two changes, then f(P) goes up by 2, stays constant or down by 2.This also explains why we need to do two simulations — if two elements in the original array are the same, then we label them (x, x') in one simulation and (x', x) in the other simulation. Then for the starting configuration, f(P) will be odd for one of them and even for the other, and at least one of them should work. From this we can conclude that it's impossible if both below conditions are met: there are no duplicate elements (otherwise by the above, at least one of the x, x' or x', x should work) the original permutation has f(P) odd (then it can never reach 0 since it's always odd)
•  » » » » » 10 days ago, # ^ |   +5 Got it! Thanks a lot for the wonderful explanation.
 » 10 days ago, # | ← Rev. 8 →   -26 The tasks is interesting! Problem A: Result: ((n — x) / x) * x + y85303459Problem B: n = 1 => impossile (0) n >= 1 impossible n <=> n * 2 ^ x = 6 ^ y (x >= 0 and y >= 1) <=> n = 2 ^ (y — x) * 3 ^ y Therefore condition is exp (2) <= exp (3) and n (that time) != 1Result: x + y = 2 * exp (3) — exp (2)85350815
 » 10 days ago, # |   -6 Really enjoyed this round. hail vovuh
 » 10 days ago, # | ← Rev. 3 →   -19 Deleted
•  » » 10 days ago, # ^ |   0 yes but no.
 » 10 days ago, # | ← Rev. 2 →   +15 What's the limit for compilation time? I submitted my code for E2 nearly the end of contest and got this verdict. "Can't compile file: Compilation process timed out." I guessed the reason is that my code is too long, but I don't think I can make it significantly shorter. Do you know how to make it compile?85381670
•  » » 10 days ago, # ^ |   +11 I don't think your code is too long xD https://codeforces.com/contest/1373/submission/85026680
•  » » 10 days ago, # ^ |   +27 We don't specify the exact time limit for compilation, but your solution can't be compiled on my laptop in 30 seconds or even in 1 minute. Probably, it is a bug of GCC or how your solution is written. Try to fix it and submit again.
•  » » » 10 days ago, # ^ |   +3 I manage to make it compile now. Thanks for reply! The reason is I wrote this in my segment tree code. node sg[nax << 2] = {}; erase "= {}" part fix the issue. I write this since I think it can prevent UB sometimes, probably it causes me UB this time...
 » 10 days ago, # |   +1 Can someone tell me where my code is wrong for E1? https://codeforces.com/contest/1374/submission/85384974
•  » » 10 days ago, # ^ |   +1 what if they only read from both books. what would be your answer, you will print INT_MAX which is wrong
•  » » » 10 days ago, # ^ |   +1 so add this to your code if ( k < both.size() ) ans = both[k] ;
•  » » » » 10 days ago, # ^ |   0 Can you give an example test case? I'm not sure I understand what you are saying because the loop would take care of the case where they read from both books (when i = k)
•  » » » » » 10 days ago, # ^ |   0 check out this case, you code will produce negative value. because $k - i$ is negative and you index the vector with negative indices. Spoiler15 1 5 1 1 5 1 1 5 1 1 5 1 1 5 1 1 5 1 1 5 1 1 5 1 1 5 1 1 5 1 1 5 1 1 5 1 1 5 1 1 5 1 1 5 1 1
•  » » 10 days ago, # ^ |   0 what if both is empty?
•  » » » 10 days ago, # ^ |   0 sorry, i misread it
 » 10 days ago, # |   -14 Please a fast editorial , i need to upsolve
 » 10 days ago, # |   -15 Really not enjoy Math-intensive problems... I suggest every contest (especially for DIV3) add a Math index to indicate how much questions are Math-related.
 » 10 days ago, # | ← Rev. 2 →   0 What is the test 4 of problem E like ?I tried to use priority_queue a(only a like), b(only b like), c(both a and b like)Then with ca(number of chosen a), cb(number of chose b) If (ca < k), I will take min if exist (a.top() and c.top()) If (cb < k), I will take min if exist (b.top() and c.top()) If (c.top()) is selected I will increase both (ca) and (cb) else I only increase 1 (a.top() -> ca and b.top() -> cb)
•  » » 10 days ago, # ^ |   0 Even I did the same priority_queue thing. But got stuck at test case 5.
•  » » » 10 days ago, # ^ |   0 Check this out: https://codeforces.com/contest/1374/submission/85356629I did the same with priority queue:)
•  » » 10 days ago, # ^ |   0 I failed at tc 4 too with priority_queue too because i forgot to convert it into the ascending one.
 » 10 days ago, # | ← Rev. 2 →   0 E2 would have been better easier if it didn't have to traceback indexes.
•  » » 10 days ago, # ^ |   +10 If you really think so, then try this
•  » » » 10 days ago, # ^ |   +16 Hi! Thank you so much for sharing the problem! It feels good to know my approach for E2 was correct!Though had to add a few extra steps because of coordinate compression.Here's my submission for 799-E -- 85410030 (solved using two BITs , same as E2)Although my thought still remains, tracing back through BIT would have sucked :pThanks!
 » 10 days ago, # |   0 What a huge implemention on E1.Three pointers and so many if-else, I am about to not to solve it. Luckily, before the end of the contest I finally solved it by huge implemention :), hope not to be FST.
•  » » 10 days ago, # ^ |   +1 I think instead of using 3 pointers, you can just iterate over how many books are you taking which Alice and Bob both like. Then it is obvious that you have to take k — (both likes) books from 1 0 and 0 1. Just precalculate the prefix sums.
•  » » » 10 days ago, # ^ | ← Rev. 2 →   +3 I have done the same but it gives WA on test case 5. can you please check it 85387758upd : missed case (0,0)
•  » » » » 10 days ago, # ^ |   0 Instead of else b.push_back(t), you have to use else if(B==1) b.push_back(t)Because you are also pushing 0 0 values into b, where no one likes the book. Instead, you should push 0 1 values into b, where Bob likes the book.I slightly changed your code according to the above logic. Check 85389515.
•  » » » 10 days ago, # ^ | ← Rev. 4 →   +10 Yup, there are many ways to solve E1 with easy implementation. You can even just take the minimum number of commonly liked books initially, then keep replacing the two longest individually liked selections with the shortest one commonly liked one remaining if it makes the answer better.
•  » » 10 days ago, # ^ |   +1 You could have implemented it directly using priority queue, one for each of the possible cases.Then greedily go through the input :)
•  » » 10 days ago, # ^ |   +8 Hi! I think the approach for E1 was fairly straighforward. (maybe) I stored time for (0,1) , (1,0) and (1,1) in different arrays and sorted them by non decreasing order of time. Also we don't need to store (0,0) (why?)Say we can take x amount of (1,1) then we know we have to take k-x from (0,1) and (1,0).Let's iterate over all possible case of x and the minimum possible time is answer.Here's my submission : 85342055 Thanks!
•  » » » 10 days ago, # ^ |   0 shit... I didn't consider the x factor. I knew that taking all of both would be wrong but then I went into some other direction.
•  » » » 10 days ago, # ^ |   +8 Thanks. Best solution for me at least.
•  » » » 10 days ago, # ^ | ← Rev. 2 →   0 Tried doing something different but on the same lines Took Three separate vectors for (0,1) , (1,0) and (1,1) , and sorted them Then took a variable which would store the answer , NowIterate over three vectors at the same time , keeping variable i for 1,1 and j for 0,1 and 1,0if time amount of (1,1) at i is greater than time amount of ((0,1) + (1,0)) at j then add (0,1) + (1,0) at j and j++ else add (1,1) and i++But getting WA on test 8Here's my code 85373064
•  » » » » 10 days ago, # ^ | ← Rev. 2 →   0 My implemention is:1. Can (1,1) replace (0,1)+(1,0)? (1) (1,1) <=(0,1)+(1,0) (2) One of them run out of their "own like" set which means the book only he likes, but he still needs to read book, so just put (1,1) dont need to check anything.2. Can (1,1) replace (0,1) or (1,0)In this situation, one of them has got k books to read but the other is not. Just check (1,1)<=(0,1) or(1,1)<=(1,0), then just choose (1,1)3. Otherwise we just choose the book in their "own like" setPS: we also have to check whether the set (1,1) has run out, if so we just go to 3, and get the number of books we need, because we have checked the exist of answer before, which is put all the referenced books in the shared set and check whether both of them have k books to read.
•  » » » » » 10 days ago, # ^ |   0 Thanks for the answer , but I dont think you saw my submissionThere was only one typo in a loop (wrote i instead of i1) and Nothing wrong with the logic , got AC Iam not completely sure if I understand your 2nd point thoughThanks for the effort of commenting though
•  » » » 10 days ago, # ^ |   0 I have also done similar thing. Here's my video Editorial for E1 Video Link
•  » » 10 days ago, # ^ |   +3 You overkilled it.
•  » » 10 days ago, # ^ |   0
 » 10 days ago, # |   0 How to Solve F ?
 » 10 days ago, # | ← Rev. 2 →   0 Why am I getting TLE on test case 8? 85389867
•  » » 10 days ago, # ^ |   +1 may be your while(1) loop run for long time(>2000ms)
•  » » » 10 days ago, # ^ |   0 Even now I'm getting TLE. I've tried using very large random test cases. It works for them, but I can't figure out what's causing TLE here
•  » » » » 10 days ago, # ^ |   +1 try with map instead of unordered_map
•  » » » » 10 days ago, # ^ |   0 Try using map instead of unordered_map. unordered_map takes O(n) time to search in the worst case but map takes O(log n)
•  » » » » » 10 days ago, # ^ |   0 Yeah, works now! :(
 » 10 days ago, # | ← Rev. 2 →   0 D: Could someone please tell why this is giving TLE?http://codeforces.com/contest/1374/submission/85383846inline bool c(ll a, ll b) { return (a >= b); }int main() { ll t; scanf("%lld", &t); while(t--) { ll n, k; scanf("%lld %lld", &n, &k); ll p = 0; unordered_map mxx; for(ll i = 0; i < n; i++) { ll x; scanf("%lld", &x); x = x % k; if(x == 0) continue; x = k - x; mxx[x]++; } for(auto i: mxx) { ll v = i.first + k * (i.second - 1) + 1; p = max(p, v); } printf("%lld\n", p);} }
•  » » 10 days ago, # ^ |   +14 Try using map instead of unordered_map. Because unordered map has a worst case complexity of O(n), your code has a worst case complexity of O(n^2).
•  » » » 10 days ago, # ^ |   0 Wohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh, sorry to spam, it blew my mind, Thanks a lot sir, could you please tell when to use map or unordered_map?
•  » » » » 10 days ago, # ^ |   +4 PS: I got acceptedhttp://codeforces.com/contest/1374/submission/85388466
•  » » » » 10 days ago, # ^ |   +2 In my experience, always use map instead of unordered map, since it gives you a complexity of O(lgn) every time.Also you would like to read this: https://codeforces.com/blog/entry/62393It uses a custom hash, to avoid getting TLE when using unordered map :)
•  » » » » » 10 days ago, # ^ |   0 thank you sir :)
•  » » » 10 days ago, # ^ |   0 Didn't realise this stupidity of mine. Worked around it by using reserve() upto 1e4. I guess it will be hacked.I am so stupid I thought unordered_map is obviously faster than map always :|
•  » » 10 days ago, # ^ |   0 Use custom hash with ordered_map. It will be accepted
 » 10 days ago, # |   +4 I see C easier than A ;) :v
•  » » 10 days ago, # ^ |   0 It seems to me also.
•  » » 10 days ago, # ^ |   0 Can you explain me C I feel so stupid :(
•  » » » 10 days ago, # ^ |   0 Here check out my video solution. It is time stamped so just skip to C.
•  » » » 10 days ago, # ^ |   0 the input is string with only opening and closing brackets, strings like () , (()), ()(())() are regular strings but there are some inputs not regular your task to count the minimum moves to make it regular , for example: )( here you need one move to make it regular , ))()()(( here you need two moves to make it regular right :) and so on... I hope this is useful for you, and don't say stupid again i hate this word, no one stupid, there are some can understand from first time and others after two or more times just practice more that's make you very fast for reading and understanding problems , Good Luck ^_^
•  » » » 10 days ago, # ^ | ← Rev. 2 →   0 Its a standard question of matching brackets. Google it you'll find it
 » 10 days ago, # |   0 https://codeforces.com/contest/1374/submission/85372487I think this solution is linear. Anyone explain the reason for TLE?
•  » » 10 days ago, # ^ |   +1 use map instead of unordered_map
•  » » 10 days ago, # ^ |   0 I was thinking that unordered_map is faster than map? Can anyone make me clear?
•  » » » 10 days ago, # ^ |   0 Check this out https://codeforces.com/blog/entry/79433?#comment-652083
•  » » » 10 days ago, # ^ |   0 unordered map can take anywhere between o(1) to o(n). while map takes o(logn) always.
 » 10 days ago, # |   0 Why am I getting TLE in this submission for Question D? My Submission
•  » » 10 days ago, # ^ |   0 Use map instead of unordered_map
 » 10 days ago, # |   0 For D ,Even O(n*t) solution is resulting in TLE , Is there still any scope left for improvement in my code . Code#include #include #define ll long long using namespace std; void solve() { ll n,k; cin>>n>>k; ll m=-1; ll a; ll ans=0; unordered_map v; for(ll i=1;i<=n;i++) { cin>>a; if(a%k!=0) { ll r1 = a%k ; ll r2 = k-r1; if((k*v[r2])+r2 > m) { m = (k*v[r2])+r2 ; } v[r2]++; } } ans = m+1; cout<>t; while(t--) { solve(); } }
•  » » 10 days ago, # ^ |   +1 using map instead of unordered_map, got it Accepted, But could anyone pls explain why did it happen?
•  » » » 10 days ago, # ^ |   0 Don't use unordered_map or unordered_set they blow up for certain inputs , if you want a detailed explanation read this blog
•  » » » 10 days ago, # ^ |   0 Check out this blog. Basically, unordered_map offers constant time operations on average when it is known that the inputs are fairly randomised. However, it is possible to make test cases such that collisions become very likely, resulting in linear time operations, thus blowing up complexity.
 » 10 days ago, # | ← Rev. 2 →   0 What's wrong with this code. (Problem D) It gives MLE at test case 5. Thanks in advance.
•  » » 10 days ago, # ^ |   +5 because you create many map keys. For Example fre = {{1, 4}, {100000, 3}}, k = 1000000 You are created keys 2, 3, 4 .... 1000000. if(fre[num] > 0) created this keys
•  » » » 10 days ago, # ^ | ← Rev. 2 →   0 Thanks got it.
•  » » » » 10 days ago, # ^ |   0 You must refer to the next element. By the way, such a solution will not work even in time. use binary search to find the element closest to the current element x. After it has reached the required value. So the asymptotic will become nlog (n), not kn
 » 10 days ago, # |   +2 How to solve D if the first operation can be performed any number of times on each $i$.
•  » » 10 days ago, # ^ |   0 Pls do not bother about it
•  » » 10 days ago, # ^ |   0 You mean [k = 3, a = {2, 2, 2, 2}]?
•  » » » 10 days ago, # ^ |   0 I mean let's say $k$ = 4 and $a$ = $[1,4,8]$. In original problem answer would be 4 because we can perform operation $a_i = a_i + x$ on a particular $i$ at most once. How to solve it if we can perform it any number of times. Like in this case answer would be 3 as we can perform $a_1 = a_1 + 1$ and $a_1 = a_1 + 2$.
•  » » 10 days ago, # ^ |   0 If x is answer to the current question, then an O(x).k solution can be easily found for the modified question. We maintain a frequency array of size k, to store the remainders and another frequency array of size k to store currently available remainders . While processing x, we can check if it can make a remainder which is needed, and we can modify accordingly.
•  » » 10 days ago, # ^ |   0 I initially didn't read that line and was getting hopeless. I mean there won't be any fast algorithm, I have a felling that there won't be any polynomial time algorithm
 » 10 days ago, # |   -14 My A, B, C, D, E1 solution`s A: 85388328 B: 85388390 C: 85388427 D: 85388457 E1:85388485 If you have questions regarding the logic of the solution or the principle of the code — write here
•  » » 10 days ago, # ^ |   +3 Why am I getting TLE in this submission for Question D?My Submission
•  » » » 10 days ago, # ^ |   +3 Because worst case time complexity of unordered map in order of n . Solve it by using map
•  » » » 10 days ago, # ^ | ← Rev. 2 →   0 I didnt fully understand the reason, but its in unordered_map. Use the common map and it will work. I will now try to understand why you cannot use unordered_map. P.S. I understood the reason. In some cases, unordered_map works for a long time
•  » » 10 days ago, # ^ |   0 E1 -> simple and easy implementation. Should have clicked this.
•  » » 10 days ago, # ^ |   0 In E1, is it always necessary to take A and B in pair?
•  » » » 10 days ago, # ^ |   0 Yes. Since we write the values ​​in set, this will be the most profitable solution.
 » 10 days ago, # |   +1 Tutorial of problem C: First, solve this, then assume your output is $ans$. Now, back to C, and print $(n-ans)/2$ for each testcase. I wish I've made a clear solution and stay tuned for my YouTube channel :'D
 » 10 days ago, # |   +11 Can someone help me in finding bug in my E2(Hard Version) solution? Here is my solution 85387601 It is failing in 12th test case. Thanks in advance.
•  » » 10 days ago, # ^ |   0 Our solution seems to have the same idea. Even my solution is failing on test 12, with the same answer. If someone could help it would be great, thanks
 » 10 days ago, # | ← Rev. 2 →   -65 Can anyone please tell me what's wrong with my solution in E2??giving RE on test case 5.https://codeforces.com/submissions/Lord_Saga
•  » » 10 days ago, # ^ |   +7 Next time use spoiler or link to share code.
•  » » 10 days ago, # ^ |   +6 I like this comment //FIRST THINK THEN CODE.
•  » » 10 days ago, # ^ |   0 So big comment,hard to read for every-one. Edit it using spoiler & block option or give the code link..
 » 10 days ago, # |   -62 Question D should be rejudged , as it has extreme time limits , there are people who used map , passed their tasks , while i got TLE using unordered_map , which is faster . In O(n*t) time limit , even the time complexity to take input is O(n*t) , there is no way my solution should fail . Definitely , There is a big scandal behind all this . We want Enquiry. Hope , Mike sir will look into this matter .
•  » » 10 days ago, # ^ | ← Rev. 3 →   +16 Unordered map can run in O(n) per query in the worst case if there are enough collisions. It is trivial to generate cases that cause such behavior for unordered map without custom hashes and would make the solution run in O(t * n ^ 2).CF blog that discusses this.
•  » » 10 days ago, # ^ |   +40 "Definitely , There is a big scandal behind all this"Maybe in your mind.
•  » » 10 days ago, # ^ |   0 unordered maps are not always faster than maps, as ordered maps can take anywhere between o(1) to o(n) for indexing while maps always take o(logn).
•  » » 10 days ago, # ^ |   0 So, How come don' I see any attempt at this contest in your account?
•  » » » 10 days ago, # ^ | ← Rev. 2 →   0 Here is my code , i did on my real account . It passed with map as suggested in above comment . I was not aware about blowing property of unordered map . Code#include #include #define ll long long using namespace std; void solve() { ll n,k; cin>>n>>k; ll m=-1; ll a; ll ans=0; unordered_map v; for(ll i=1;i<=n;i++) { cin>>a; if(a%k!=0) { ll r1 = a%k ; ll r2 = k-r1; if((k*v[r2])+r2 > m) { m = (k*v[r2])+r2 ; } v[r2]++; } } ans = m+1; cout<>t; while(t--) { solve(); } }
 » 10 days ago, # | ← Rev. 2 →   +2 what a bad day for me, my rating continously decreasing from past 4-5 contest and my current rating is just 1615 and this contest is unrated for me in which my rank would be in top 10. hope this would never happened to anyone
 » 10 days ago, # |   0 is vovuh from BTS?
 » 10 days ago, # |   +21 I'm going to assume that my solution for problem E2 using treap is not the intended one, because that would be very weird for a div3 contest. But I usually try to kill a mosquito with a bazooka during contests, so I'm sure that there is a simpler and nicer way to solve the problem :P
•  » » 10 days ago, # ^ |   0 Can you please explain your treap solution?
•  » » » 10 days ago, # ^ |   +9 Fix the amount of books of type 1-1 that you will take. You can calculate how many books of type 1-0 and 0-1 you will need to force that both people have at least k books. Obviously, you will take the ones that have lower cost for each group of books. This works for E1.Now for E2, you should keep the same strategy, but maybe you have to use a few more books to complete the M books you need to take. But both people already have at least K books, so you can take any other book you want (even if it is a 0-0 book). Obviously, you will take the smallest amount of books you need (let's say X). Here is where treap comes up to help us: you can use it to calculate the sum of the first X smallest values in the remaining books that you didn't take before.
•  » » » » 10 days ago, # ^ | ← Rev. 2 →   0 but why didn't u implement it??????
•  » » » » » 10 days ago, # ^ |   +3 You can see my submission during contest here :)If you are looking for a clean implementation, don't even waste time with my code. I was on a hurry because the contest was reaching its end, so I had to code everything quickly :P
•  » » » » 10 days ago, # ^ |   0 But how do you save the indices of solution set of books? I could calculate the minimum answer using set, but couldn't figure how to find the indices of final answer.
•  » » » » » 8 days ago, # ^ |   0 You can keep track of the number of 1-1 books in the optimal solution, sort the unchosen books, and take the smallest m-k books, print them along with the chosen books
 » 10 days ago, # |   0 Can someone explain how to solve E2? I saw some people using treap to solve the problem.
•  » » 10 days ago, # ^ | ← Rev. 4 →   +7 I think the main part of this problem is how to find k-smallest elements sum. Usually you can do this by binary search tree, so treap can do the job. The easiest way to implement for me is to use segment tree that each node store pair of (number of element, sub of element) in subtree. To get sum of k-smallest elements. Check if left node size greater than k or not. If yes, try searching on left subtree, otherwise subtract sum of left subtree and search on right subtree. Fenwick tree can also do the job if you keep two fenwick trees that one store sum and one store number of elements and use binary lifting or binary search to find sum of k-smallest elements.I saw many people solve using priority_queue or multiset, but I don't know how it works though.Edit: I think I get it now. It’s similar to finding median by priority_queue or multiset. Notice that k is always increasing. So you can simply do the same thing. When you encounter query, just transfer elements between 2 multiset respected to value of k. The total number of operations will still be $O(n)$
 » 10 days ago, # | ← Rev. 2 →   +3 Thanks for this contest! Through this contest, I realized that my implementation skill is very very weaker than others In F, I observed the main idea very quickly, but that is all.. I failed to write accurate code...
•  » » 10 days ago, # ^ |   +8 can you tell your idea for solving F?
•  » » » 10 days ago, # ^ | ← Rev. 2 →   0 For(int e=1;e<=n-2;e++), we find the Farthest minimum value that located in [e~n]. And located in e After that, if the array is sorted, finished. but if not, last two number is not sorted. so in this case, we find two same value in [1~(n-2)] and maximum in last two number is going to that ( we can go either of two same value ) then we only go fowrad one move -> then maximum value can go to last of array
•  » » » » 9 days ago, # ^ |   0 thanks, I was thinking about the same idea
•  » » 10 days ago, # ^ |   -23 Your code for E2 is a mess!
•  » » » 10 days ago, # ^ |   0 my code?
•  » » » » 10 days ago, # ^ |   0 No, Taehooooon's.
•  » » » » » 10 days ago, # ^ |   0 i can't solve E2
•  » » » » » 9 days ago, # ^ |   -8 he didn't solve E2
•  » » 10 days ago, # ^ |   0 I also face the same issue, for questions rated above 1500-1600. Can anyone provide some tips?
•  » » » 10 days ago, # ^ |   0 practice question of difficulty :1600 or above.
•  » » » 10 days ago, # ^ |   0 look at the code of more experienced people. They usually know how to make it in a simple way.
 » 10 days ago, # |   0 https://codeforces.com/contest/1374/submission/85392451 its showing TLE for using map also. pls someone find the fault.
•  » » 10 days ago, # ^ |   0 K can be up to $10^{9}$
•  » » » 10 days ago, # ^ |   0 ok yaa. thanks
•  » » 10 days ago, # ^ |   0 Hey, You are running a for loop from 1 to k (1 <= k <= 10^9) This is the reason for TLE. Instead of going through all the numbers from 1 to k just check for those which are present in the map.
•  » » » 10 days ago, # ^ |   0 ya got it. Thanks.
 » 10 days ago, # |   0 Can anyone tell me why I am getting this runtime error in TC 5 for E1 ?Link for submission — https://codeforces.com/contest/1374/submission/85375093I am pretty sure this has to do something with my comparator function for sort but I cannot figure it out.
•  » » 10 days ago, # ^ |   +3 This might be what you need.
 » 10 days ago, # | ← Rev. 3 →   0 Can someone help me with D? I am not able to understand what's wrong with my code. Main logic belowlli == long long int lli mx = 0, mxval = 0; map mp; while(n--) { lli x; cin>>x; if(x % k == 0) continue; lli diff = (k - x%k)%k; mp[diff]++; if(mp[diff] >= mx) { mx = mp[diff]; if(diff >= mxval) mxval = diff; } } if(mx == 0 and mxval == 0) cout<<0<
•  » » 10 days ago, # ^ |   0 You should skip elements with diff = 0.
•  » » » 10 days ago, # ^ |   0 diff=0 when (k - x%k). I don't think it will ever be 0
•  » » » » 10 days ago, # ^ |   0 Consider the case $x \bmod k = 0$.
•  » » » » » 10 days ago, # ^ |   0 That won't be because the code will not go to that line then. I have checked it in the line above.
•  » » » » » » 10 days ago, # ^ |   0 Ops, you're right.
•  » » » » » » » 10 days ago, # ^ |   0 Yes, I still don't know though why my code is WA :(
•  » » 10 days ago, # ^ | ← Rev. 4 →   0 Seems that the mistake is in: if(mp[diff] >= mx){ mx = mp[diff]; if(diff >= mxval) mxval = diff; } You can do this instead: if(mp[diff] > mx || (mp[diff] == x && diff > mxval) ) { mx = mp[diff]; mxval = diff; } The reason is that if mp[diff] > mx and diff < mxval you are not updating the mxval but you must do it.
•  » » » 10 days ago, # ^ |   0 Can you explain why I should update mxval when mp[diff] > mx and diff < mxval. Cause mxval should also be 'max' right? so should be update when mp[diff] >= mx and diff >= mxval
•  » » » » 10 days ago, # ^ |   0 You need to take the maximum mp[diff] no matter what. Then, over all the diff which have the maximum value mp[diff] you should take also the maximum. Consider this case: 3 3 1 2 2 Correct output: 5. That is because the correct results are mx = 2 and mxval = 1, but in your code it gives mx = 2 and mxval = 2 which is incorrect. If you still don't get it just do the simulation by hand.
•  » » » » » 9 days ago, # ^ |   0 Hi, I was able to solve the question now. What a stupid mistake from my part. Thanks so much for your help :)Also I saw you became Expert after this round, congratulations!
 » 10 days ago, # | ← Rev. 4 →   +4 Here is my screencast of this contest, do check out it :)On my channel I do educational content, so if you want to improve, make sure to subscribe to the channel!
 » 10 days ago, # |   -22 My solutions for A,B,C,D,E1 A -> A B -> B C-> C D -> D E1 -> E1
•  » » 10 days ago, # ^ |   0 Man, Your E1 is elegant.
 » 10 days ago, # |   0 Can Anybody explain me C please
•  » » 10 days ago, # ^ |   0 Keep a counter, initialised to zero. Traverse through the string now, whenever you encounter ( counter++, otherwise counter--Now if the counter becomes negative at any moment l, it means that you have a extra closing bracket, in this situation move it to the end of the string. This approach will ensure that every opening bracket is matched to some closing bracket. And also set the counter to 0.
•  » » 10 days ago, # ^ | ← Rev. 2 →   +3 Suppose you have variable $bal$ which stands for balance. We go through string from left to right, if we have $"("$ now then do $bal+=1$ and $bal-=1$ if we have $")"$. The answer is the global minimum value of $bal$. For example $s=)))((((())$, then balance will be $-1, -2, -3, -2, -1, 0, 1, 2, 1, 0$. The most minimal value of $bal$ was -3, thus the answer is 3. So you can fix the sequence by 3 moves. You can take 3 rightmost opening brackets and move them to the front of the string. So string $)))((((())$ will become $((()))(())$.
•  » » » 10 days ago, # ^ |   0 Hey so will the deformation always occurs in the form of )))(((, can ) or ( appear in between balanced sequences. Cause I'm unable to concretely prove it. Thanks!
•  » » » » 10 days ago, # ^ |   0 not always, you can get string like $)())())())(((($ answer is 4, and you take last 4 opening brackets and move them to the beginning, you will get $(((()())())())$
•  » » » » » 10 days ago, # ^ |   0 Got it thanks for the help :)
•  » » 10 days ago, # ^ |   0 You can use stack by popping the perfect brackets and keeping the length of unperfect brackets and print the answer by dividing the length of the stack
 » 10 days ago, # |   0 How to solve problem D ?
•  » » 10 days ago, # ^ | ← Rev. 2 →   +1 Keep a map of values that need to be added to each element to make it divisible.Now iterate over the map and if some key has multiple count,increase it by multiples of K.Now, the maximum key will be the answer. 85341803
•  » » 10 days ago, # ^ |   0 Here check my video editorial
 » 10 days ago, # |   0 Kindly explain the statement of problem E1.
•  » » 10 days ago, # ^ |   -13 Video Editorial for E1 Video Link
 » 10 days ago, # | ← Rev. 2 →   +1 using min_heap (priority_queue) for D seemed more intuitive to me. Submission
 » 10 days ago, # | ← Rev. 2 →   -14 can anyone plz try to hack my first E1 submission i think it is wrong!!upd-: never mind that solution is correct
•  » » 10 days ago, # ^ |   0 well tried hacking it but upd it is correct
 » 10 days ago, # |   0 C,though a very easy problem, had solution directly from geeksforgeeks.Link
 » 10 days ago, # |   0 Can anybody tell me why is @Vovuh so much popular? Why is everyone talking about him?
 » 10 days ago, # |   0 Can someone please tell why I'm getting TLE in D https://codeforces.com/contest/1374/submission/85394978
 » 10 days ago, # |   0 can anyone tell me the reason why this works in case of ques D when i use map and this gives TLE when i use unordered_map ..
•  » » 10 days ago, # ^ | ← Rev. 2 →   0 same issue with me too AC ,TLE . What i think the reason is for ordered map worst case time complexity is O(logn) whereas for unordered_map it is O(n)
•  » » 10 days ago, # ^ | ← Rev. 2 →   0 Use custom hash with unordered_map to avoid TLE. AC code with custom hash- Link
 » 10 days ago, # | ← Rev. 2 →   0 My Video solution for the contestA,B,C The video is time stamped for your convenience (check the description).
 » 10 days ago, # |   +35 As usual, video solutions to all problems are available at the end of my screencast of the round.
•  » » 10 days ago, # ^ |   0 Thank you for the content. Simple explanations.
 » 10 days ago, # |   0 Can anyone give a proof for the solution to F?What i used -> sort the first n — 2 part and then if the remaining 2 elements are not sorted then sort them using some element which has a duplicate. Im unable to prove why it works.
•  » » 10 days ago, # ^ |   0 Proof at 2:17:50 here
•  » » » 10 days ago, # ^ |   0 The TLDR is that the parity of inversions doesn't change
•  » » » » 10 days ago, # ^ |   0 Was just able to prove it. Amazing explanation thought. Keep up the good work!
 » 10 days ago, # |   0 have the people got the rating for this round anyone please help me
•  » » 10 days ago, # ^ |   +1 Ratings won't be updated until after the open hacking period is over.
 » 10 days ago, # |   0 In E2, I made 4 arrays, 1st is "common books", second is "books interesting Alice only", third is "books interesting Bob only" and fourth is "books both are not interested in". Then I sorted them and took corresponding books from second and third array and added them to form pairs of books that interest either one of them. After both have read 'k' books of their interest, I am checking if a total of 'm' books have been read.Let 'num' be the books read till now.My code is failing on test 12, and with furthur debugging, I found that this case is where num<=m. So now I am taking all the remaining books(common,interest for alice only,interest for bob only and books none of them are interested in) and sorting them by time. after this I am taking the first (m-num) books to get the final ans.Link to the codePlease can someone help me in debugging. Thanks
•  » » 10 days ago, # ^ |   0 That approach isn't necessarily correct. You might want to remove a book interesting to both people and replace it with two books, one interesting to each person.
•  » » » 10 days ago, # ^ |   0 at each step, I am checking if the common book has a lower time or the combined time of 2 books each interesting to one person. This approach worked for me in E1.
•  » » » » 10 days ago, # ^ | ← Rev. 2 →   +9 Imagine this testcase for E2:4 2 13 1 04 0 15 0 06 1 1Your approach probably will print 9 (1, 4) as 6 < 3 + 4 but the answer is 7 (1,2).
•  » » » » » 7 days ago