AcWing 1241. 外卖店优先级
原题链接
简单
作者:
不知名的fE
,
2024-11-23 17:51:13
,
所有人可见
,
阅读 1
样例
import java.util.*;
public class Main {
static final int N = 100010;
static int[] score = new int[N], last = new int[N];
static boolean[] st = new boolean[N];
static int n, m, T;
static ArrayList<List<Integer>> list = new ArrayList<>();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), m = sc.nextInt(), T = sc.nextInt();
sc.nextLine();
for (int i = 0; i < m; i++) {
String[] s = sc.nextLine().split(" ");
list.add(Arrays.asList(Integer.parseInt(s[0]), Integer.parseInt(s[1])));
}
list.sort((o1, o2) -> {
if (o1.get(0).equals(o2.get(0))) return o1.get(1) - o2.get(1);
else return o1.get(0) - o2.get(0);
});
for (int i = 0; i < m; i++) {
int j = i;
while (j < m && list.get(i).equals(list.get(j))) j++;
int t = list.get(i).get(0), id = list.get(i).get(1), cnt = j - i;
i = j - 1;
score[id] -= t- last[id] - 1;
if (score[id] < 0) score[id] = 0;
if (score[id] <= 3) st[id] = false;
score[id] += cnt * 2;
if (score[id] > 5) st[id] = true;
last[id] = t;
}
for (int i = 1; i <= n; i++)
if (last[i] < T) {
score[i] -= T - last[i];
if (score[i] <= 3) st[i] = false;
}
int cnt = 0;
for (int i = 1; i <= n; i++)
if (st[i]) cnt++;
System.out.println(cnt);
}
}