Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ll last_cow = arr[0].first;
- ll interval = 0;
- for (int i=1; i<N; i++) {
- // First try placing the cow in the current interval
- ll lowest_pos_new_loc = last_cow + val;
- if (lowest_pos_new_loc <= arr[interval].second) {
- last_cow = lowest_pos_new_loc;
- continue;
- }
- // Need to find the next interval to place the cow
- while (interval < M && arr[interval].second > lowest_pos_new_loc) {
- interval ++;
- }
- // Case 1: we ran out of intervals
- if (interval == M) return false;
- last_cow = max(lowest_pos_new_loc, arr[interval].first);
- }
- return true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement