File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ public static void main (String [] args ) throws IOException {
7+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
8+ StringTokenizer st = new StringTokenizer (br. readLine());
9+ int N = Integer . parseInt(st. nextToken());
10+ int L = Integer . parseInt(st. nextToken());
11+
12+ int [][] sections = new int [N ][2 ];
13+ for (int i = 0 ; i < N ; i++ ){
14+ st = new StringTokenizer (br. readLine());
15+ sections[i][0 ] = Integer . parseInt(st. nextToken());
16+ sections[i][1 ] = Integer . parseInt(st. nextToken());
17+ }
18+ Arrays . sort(sections, (a, b) - > a[0 ] - b[0 ]);
19+ int coveredEnd = 0 ;
20+ int answer = 0 ;
21+
22+ for (int i = 0 ; i < N ; i++ ){
23+ int start = sections[i][0 ];
24+ int end = sections[i][1 ];
25+ if (coveredEnd >= end){
26+ continue ;
27+ }
28+
29+ int realStart = Math . max(coveredEnd, start);
30+ int remain = end - realStart;
31+ int count = remain / L ;
32+ if (remain % L != 0 ){
33+ count++ ;
34+ }
35+ answer += count;
36+ coveredEnd = realStart + count * L ;
37+ }
38+
39+ System . out. println(answer);
40+ }
41+ }
42+
43+ ```
You can’t perform that action at this time.
0 commit comments