Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package weblab;
- import java.util.*;
- class Time {
- int time;
- int start; // 1 - true, 0 - false
- public Time(int time, int start) {
- this.time = time;
- this.start = start;
- }
- }
- class Solution {
- public static int fixMyBikesPlease(int n, int[] starttimes, int[] durations) {
- List<Time> times = new ArrayList<>();
- for (int i = 1; i <= n; ++i) {
- times.add(new Time(starttimes[i], 1));
- times.add(new Time(starttimes[i] + durations[i], 0));
- }
- Collections.sort(times, Comparator.comparing((Time t) -> t.time).thenComparing((Time t) -> t.start));
- int Max = Integer.MIN_VALUE;
- int currently_in_service = 0;
- for (Time t: times) {
- if (t.start == 1) {
- currently_in_service ++;
- Max = Math.max(Max, currently_in_service);
- }
- else
- currently_in_service --;
- }
- return Max;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement