Qiyu111 @ 2023-04-21 22:50:04
java
import java.util.*;
class Plant_trees {
public static void main (String args[]){
Scanner sc = new Scanner(System.in);
int a,b;
a = sc.nextInt();
b = sc.nextInt();
int []start = new int[b];
int []end = new int[b];
for(int i = 0;i<b;i++){
start[i] = sc.nextInt();
end[i] = sc.nextInt();
}
int []tree = new int[a+1];
for(int i=0;i < a+1;i++){
tree[i] = 1;
}
for(int i = 0;i < b;i++){
for(int j = start[i];j <= end[i];j++){
if(tree[j]==1){
tree[j] = 0;
}
}
}
int count = 0;
for(int i = 0;i < a+1;i++){
if(tree[i]==1){
count++;
}
}
System.out.println(count);
}
}
by 夜寒 @ 2023-05-14 17:55:28
提交的时候把类名 Plant_trees改成Main