https://pintia.cn/problem-sets/994805046380707840/exam/problems/1649748772841508873?type=7&page=1
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
typedef vector<long long> VI;
#define int long long
#define INF 0x3f3f3f3f
#define endl '\n'
#define N 200010
const int mod = 1e9 + 7;
ll ksm(ll a, ll b) {
ll ans = 1;
for (; b; b >>= 1LL) {
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
}
return ans;
}
ll lowbit(ll x) {
return -x & x;
}
int p[N], si[N];
int find(int x) {
if (x == p[x])return p[x];
p[x] = find(p[x]);
return p[x];
}
//size[find(b)] += size[find(a)];
//p[find(a)] = find(b);
void solve() {
int n, c;
cin >> n >> c;
int res = 0;
priority_queue<int> q;
for (int i = 1; i <= n; i++) {
string s;
int x;
cin >> s >> x;
cout << s << " " << x / c + (x % c ? 1 : 0) << endl;
res += x / c;
if (x % c)q.push(x % c);
}
vector<int> sc;
while (!q.empty()) {
int t = q.top();
q.pop();
int ok = 0;
for (int i = 0; i < sc.size(); i ++) {
if (t <= c - sc[i]) {
sc[i] += t;
ok = 1;
break;
}
}
if (!ok) {
res ++;
sc.push_back(t);
}
}
cout << res << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T --)
solve();
return 0;
}