#include <bits/stdc++.h>
using namespace std;
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const int N = 1e6+7;
#define int long long
int a[N];
int b[N];
int index1=0;
int n,c;
int ans;
signed main()
{
IOS;
cin>>n>>c;
for(int i=1;i<=n;i++){
string s;
cin>>s>>a[i];
int p=a[i]/c;
ans+=p;
if(a[i]%c)p++;
cout<<s<<" "<<p<<endl;
a[i]%=c;
}
sort(a+1,a+1+n,[&](int A,int B){
return A>B;
});
for(int i=1;i<=n;i++){
int t=0;
if(a[i]==0)break;
for(int j=1;j<=index1;j++){
if(b[j]+a[i]<=c){
t=1;
b[j]+=a[i];
break;
// cout<<j<<" "<<b[j]<<endl;
}
}
// cout<<t<<endl;
if(!t)b[++index1]=a[i];
// for(int k=1;k<=index1;k++)cout<<b[k]<<" ";
// cout<<endl;
}
cout<<ans+index1;
return 0;
}
L2-046 天梯赛的赛场安排分数 25
最新推荐文章于 2024-10-17 15:47:06 发布