#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 5010, M = 510;
bool cmp (int a, int b) {
return a > b;
}
int n, c;
int v[N], h[N];
int res, cnt, k;
int main(void) {
scanf("%d%d", &n, &c);
for (int i = 0; i < n; i++) {
char ch[M];
int x;
scanf("%s %d", ch, &x);
printf("%s %d\n", ch, (x / c) + ((x % c) ? 1 : 0));
res += x / c;
if (x % c) {
v[k++] = x % c;
}
}
sort(v, v + k, cmp);
for (int i = 0; i < k; i++) {
int f = 1;
for (int j = 0; j < cnt; j++) {
if (v[i] <= c - h[j]) {
h[j] += v[i];
f = 0;
break;
}
}
if (f) h[cnt++] = v[i];
}
cout << res + cnt << endl;
return 0;
}
不需要存储字符串和所有学校的学生人数;
计算最后新增的不满的考场时, 只需要利用余数部分