import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { void solve(int N,int M,int[] X,int[] A,int[] B) { ArrayList[][] list=new ArrayList[2][100001]; for (int i=0;i(); int over3=0; int over2=0; for (int i=0;i=2) ++over2; if (X[i]+1>=3) ++over3; list[0][A[i]].add(i); list[1][B[i]].add(i); } int[] solve=new int[N]; Arrays.fill(solve, 1); int sb=0; int sa=100001; int ans=Integer.MAX_VALUE/3; while(true) { while (sb<=100000) { // over2>=Mが成り立つギリギリまでsbを大きくする。 int nover2=over2; int nover3=over3; for (int i:list[1][sb]) { if (solve[i]+X[i]==2) --nover2; if (solve[i]+X[i]==3) --nover3; } if (nover2>=M) { over2=nover2; over3=nover3; for (int i:list[1][sb]) --solve[i]; ++sb; } else { break; } if (over2>=M) ans=Math.min(ans, over3); } --sa; if (sa==-1) break; for (int i:list[0][sa]) { if (solve[i]+X[i]==1) ++over2; if (solve[i]+X[i]==2) ++over3; ++solve[i]; } } System.out.println(ans); } void run() { Scanner sc=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int N=sc.nextInt(); int M=sc.nextInt(); int[] X=new int[N]; int[] A=new int[N]; int[] B=new int[N]; for (int i=0;i