🤠 原题链接
🤠 避坑:花一天可以浇 n 次,不仅仅是 0 1 2
import java.util.*;
public class Main
{
static int N = (int) 1e5 + 10;
static int[] A = new int[N];// 差分数组
static int[] B = new int[N];// 前缀和数组
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();// 假期天数
int m = sc.nextInt();// 人数
for (int i = 0; i < m; i++)
{
int a = sc.nextInt();
int b = sc.nextInt();
A[a] += 1;
A[b + 1] -= 1;
}
for (int i = 1; i <= n; i++)
{
B[i] = A[i] + B[i - 1];
}
int k = 1;
for (k =1; k <= n; k++)
{
if (B[k] == 0 || B[k] == 2)
{
System.out.print(k + " " + B[k]);
break;
}
}
if (k == n+1)
System.out.print("OK");
}
}