File tree Expand file tree Collapse file tree 1 file changed +65
-0
lines changed
Expand file tree Collapse file tree 1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.util.* ;
3+ import java.io.* ;
4+
5+ public class Main {
6+
7+ // IO field
8+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
9+ static BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
10+ static StringTokenizer st = new StringTokenizer (" " );
11+
12+ static void nextLine () throws Exception {st = new StringTokenizer (br .readLine ());}
13+ static String nextToken() throws Exception {
14+ while (! st. hasMoreTokens()) nextLine();
15+ return st. nextToken();
16+ }
17+ static int nextInt() throws Exception { return Integer . parseInt(nextToken()); }
18+ static long nextLong() throws Exception { return Long . parseLong(nextToken()); }
19+ static double nextDouble() throws Exception { return Double . parseDouble(nextToken()); }
20+ static void bwEnd() throws Exception {bw. flush();bw. close();}
21+
22+ // Additional field
23+
24+ static int N , K , D ;
25+ static int [][] rules;
26+
27+ public static void main(String [] args) throws Exception {
28+
29+ ready();
30+ solve();
31+
32+ bwEnd();
33+
34+ }
35+
36+ static void ready() throws Exception {
37+
38+ N = nextInt();
39+ K = nextInt();
40+ D = nextInt();
41+ rules = new int [K ][3 ];
42+ for (int i= 0 ;i< K ;i++ ) for (int j= 0 ;j< 3 ;j++ ) rules[i][j] = nextInt();
43+
44+ }
45+
46+ static void solve() throws Exception {
47+
48+ int s = 1 , e = N , m = (s+ e)>> 1 ;
49+ while (s< e) {
50+ long cnt = 0 ;
51+ for (int [] rule : rules) {
52+ int a = rule[0 ], b = rule[1 ], c = rule[2 ];
53+ if (m < a) continue ;
54+ cnt += Math . min((m- a)/ c + 1 , (b- a)/ c + 1 );
55+ }
56+ if (cnt < D ) s = m+ 1 ;
57+ else e = m;
58+ m = (s+ e)>> 1 ;
59+ }
60+ bw. write(m + " \n " );
61+
62+ }
63+
64+ }
65+ ```
You can’t perform that action at this time.
0 commit comments