-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTest.java
150 lines (114 loc) · 4.69 KB
/
Test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import java.util.*;
public class Test {
public static void main(String[] args) {
// System.out.println(Arrays.toString(result));
// l = (Integer a, Integer b) -> a + b;
// System.out.println(l(4,5));
// System.out.println((char)('a' + 25));
String[] arr = "/a/./b/../../c/".split("/");
System.out.println("Split by / : " + Arrays.toString(arr));
arr = "/a/////./..//b///c/d".split("/");
System.out.println("Split by / : " + Arrays.toString(arr));
}
}
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result {
/*
* Complete the 'minimumTimeSpent' function below.
*
* The function is expected to return an INTEGER.
* The function accepts following parameters:
* 1. INTEGER_ARRAY comedyReleaseTime
* 2. INTEGER_ARRAY comedyDuration
* 3. INTEGER_ARRAY dramaReleaseTime
* 4. INTEGER_ARRAY dramaDuration
*/
static class Movie {
int releaseTime;
int duration;
Movie(int r, int d) {
releaseTime = r;
duration = d;
}
}
public static int minimumTimeSpent(List<Integer> comedyReleaseTime, List<Integer> comedyDuration, List<Integer> dramaReleaseTime, List<Integer> dramaDuration) {
// Write your code here
List<Movie> comedyMovies = new ArrayList<>();
for (int i = 0; i < comedyReleaseTime.size(); i++) {
comedyMovies.add(new Movie(comedyReleaseTime.get(i), comedyDuration.get(i)));
}
Collections.sort(comedyMovies, (a, b) -> Integer.compare(a.releaseTime, b.releaseTime));
List<Movie> dramaMovies = new ArrayList<>();
for (int i = 0; i < dramaReleaseTime.size(); i++) {
dramaMovies.add(new Movie(dramaReleaseTime.get(i), dramaDuration.get(i)));
}
Collections.sort(dramaMovies, (a, b) -> Integer.compare(a.releaseTime, b.releaseTime));
int minTime = Integer.MAX_VALUE;
return minTime;
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
int comedyReleaseTimeCount = Integer.parseInt(bufferedReader.readLine().trim());
List<Integer> comedyReleaseTime = IntStream.range(0, comedyReleaseTimeCount).mapToObj(i -> {
try {
return bufferedReader.readLine().replaceAll("\\s+$", "");
} catch (IOException ex) {
throw new RuntimeException(ex);
}
})
.map(String::trim)
.map(Integer::parseInt)
.collect(toList());
int comedyDurationCount = Integer.parseInt(bufferedReader.readLine().trim());
List<Integer> comedyDuration = IntStream.range(0, comedyDurationCount).mapToObj(i -> {
try {
return bufferedReader.readLine().replaceAll("\\s+$", "");
} catch (IOException ex) {
throw new RuntimeException(ex);
}
})
.map(String::trim)
.map(Integer::parseInt)
.collect(toList());
int dramaReleaseTimeCount = Integer.parseInt(bufferedReader.readLine().trim());
List<Integer> dramaReleaseTime = IntStream.range(0, dramaReleaseTimeCount).mapToObj(i -> {
try {
return bufferedReader.readLine().replaceAll("\\s+$", "");
} catch (IOException ex) {
throw new RuntimeException(ex);
}
})
.map(String::trim)
.map(Integer::parseInt)
.collect(toList());
int dramaDurationCount = Integer.parseInt(bufferedReader.readLine().trim());
List<Integer> dramaDuration = IntStream.range(0, dramaDurationCount).mapToObj(i -> {
try {
return bufferedReader.readLine().replaceAll("\\s+$", "");
} catch (IOException ex) {
throw new RuntimeException(ex);
}
})
.map(String::trim)
.map(Integer::parseInt)
.collect(toList());
int result = Result.minimumTimeSpent(comedyReleaseTime, comedyDuration, dramaReleaseTime, dramaDuration);
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}
}