celestialidiot's blog

By celestialidiot, history, 6 weeks ago, In English

Hi,

Problem : 1676E — Eating Queries

My Approach : I sorted the array in descending order and then calculated the prefix sum, and then I am using binary search to find the least element greater than x.

Can anyone please tell me why my code is giving TLE.

My Code

Thanks.

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
6 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

Pass your prefix vector by reference

»
6 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

use pass by reference of your prefix vector 162614431

»
6 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

You can use pass by reference, have vector defined globally or implement binary search in your main function. Implementing it straight in main function is much faster because calling a faction with pass by value is not very fast and you are doing it tq times (at most 150000000) instead of, possibly, zero times.

»
6 weeks ago, # |
  Vote: I like it -8 Vote: I do not like it

Try to debug yourself man