-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ02009
50 lines (46 loc) · 1.23 KB
/
J02009
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
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Other/File.java to edit this template
*/
package withouclass;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.Vector;
class Pair {
public int t;
public int d;
void input(Scanner sc) {
t = sc.nextInt();
d = sc.nextInt();
}
}
public class J02009 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Vector<Pair> v = new Vector<>();
for (int i = 0; i < n; i++) {
Pair x = new Pair();
x.input(sc);
v.add(x);
}
Collections.sort(v, new Comparator<Pair>() {
@Override
public int compare(Pair a, Pair b) {
if (a.t > b.t)
return 1;
else
return -1;
}
});
int s = 0;
for (int i = 0; i < n; i++) {
if (s < v.get(i).t)
s = v.get(i).t;
s += v.get(i).d;
}
System.out.println(s);
sc.close();
}
}