Solution to Codeforces Round #271 (Div. 2) 474B Worms With Explanation
Kindly comment if you have any other best solution or found any errors in my program.
Explanation:
In this problem, all the worms in the packs are numbered consecutively. You have to find, in which pack the 'q'th worm resides. Binary search technique should be used as the bubble sort will give you a TLE.
Steps:
- Get the number of worms in each pack in an array.
- While getting worms in each pack maintain the sum of the all the worms till that particular pack in another array s[].
- Then sort array 'S' as the binary search works only on a sorted array.
- Then get the label of the juicy worm and search it in the array 'S' using binary search.
- Repeat until finish searching all the juicy worms in the array.
Program:
// Accepted 592ms 800KB
No comments:
Post a Comment