So, I was recently trying to solve this problem: http://mirror.codeforces.com/contest/727/problem/F submission at http://mirror.codeforces.com/contest/727/submission/21647053
My algorithm should be O(n2 * logm + mlogn). First, I determine the lowest possible prefix sum for a certain row of numbers. This is done with a binary search and greedy. I binary search on the condition "If we can remove a certain number of problems, can the minimum prefix sum be greater than or equal to the target?" (This is always of form TTTT...FFF). To find that condition I greedily add numbers to a running sum, and if the running sum is less than or equal to target, I remove the smallest value that occurs before or at the current index. Then, I read all m queries and binary search for the correct answer on those.
Can anyone help me understand why I'm getting TLE? Thanks.