반응형
https://www.acmicpc.net/problem/1637
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
|
package algo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class B1637 {
static int N;
static long A, B, C;
static class Three {
long A;
long B;
long C;
public Three(long a, long b, long c) {
super();
A = a;
B = b;
C = c;
}
}
static Three tc[];
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
N = Integer.parseInt(br.readLine());
long rear = 1;
long front = 1;
tc = new Three[N];
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
A = Long.parseLong(st.nextToken());
C = Long.parseLong(st.nextToken());
B = Long.parseLong(st.nextToken());
tc[i] = new Three(A, B, C);
rear = Math.max(rear, C);
}
long end = rear;
while (front < rear) {
long mid = (front + rear) / 2;
long cnt = f(mid);
if (cnt % 2 == 1) {
rear = mid;
} else {
front = mid + 1;
}
}
if (rear == end && f(rear)%2==0) {
System.out.println("NOTHING");
} else {
System.out.println(rear + " " + (f(rear) - f(rear - 1)));
}
}
public static long f(long x) {
long cnt = 0L;
for (int i = 0; i < N; i++) {
long y = x > tc[i].C ? tc[i].C : x;
if ((y - tc[i].A) >= 0) {
cnt += 1 + (y - tc[i].A) / tc[i].B;
}
}
return cnt;
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
반응형
'ProgramSoliving' 카테고리의 다른 글
백준 : 7682 (0) | 2020.04.15 |
---|---|
백준 : 10775 (0) | 2020.04.15 |
백준 : 5213 JAVA (0) | 2020.03.17 |
백준 : 12886 (0) | 2020.03.15 |
백준 : 1086 JAVA (0) | 2020.03.14 |