ps:未解决内存上限和时间限制问题,算法这一块还有待优化
import java.util.Scanner;
public class better {
public static void main(String[]args) {
Scanner sc = new Scanner(System.in);
//N表示有多少家店,M表示有多少行输入,T表示现在的时刻
int N = sc.nextInt(), M = sc.nextInt(), T = sc.nextInt();
sc.nextLine();
//数到T;
int ts, id;
//行代表时刻,列标号代表店id-1,值代表此时刻订单数量
int[][] arr = new int[T][N];
for (int i = 0; i < M; i++) {
ts = sc.nextInt();
id = sc.nextInt();
arr[ts - 1][id - 1]++;
}
int[] best = new int[M];
//better表示下标为i+1的店的优先级且进入了缓存
boolean[] better = new boolean[N];
for (int i = 0; i < T; i++) {
for (int k = 0; k < N; k++) {
if (arr[i][k] != 0) {
for (int j = 0; j < arr[i][k]; j++) {
best[k] += 2;
}
} else {
if (best[k] != 0) {
best[k]--;
}
}
if (best[k] > 5) {
better[k] = true;
} else if (best[k] <= 3) {
better[k] = false;
}
}
}
int res = 0;
for (boolean o : better) {
if (o) {
res++;
}
}
System.out.println(res);
sc.close();
}
}