题目:Change-free
思路:
贪心。
先先假设全部用硬币支付,再用优先队列维护,当硬币数量不够时,弹出会增加的生气值最小的。
代码:
#include<bits/stdc++.h>
using namespace std;
#define maxn 100000
#define ll long long
struct Pair{
ll x,w;
bool operator < (const Pair& oth) const {
return w>oth.w||(w==oth.w&&x<oth.x);
}
Pair() {}
Pair(ll xx,ll ww){
x=xx,w=ww;
}
};
ll n,m;
ll v[maxn+5],c[maxn+5];
priority_queue<Pair> que;
ll Notes[maxn+5],Coints[maxn+5];
ll ang=0;
void readin() {
scanf("%lld%d",&n,&m);
for(ll i=1;i<=n;i++) {
scanf("%lld",&v[i]);
Notes[i]=v[i]/100;
v[i]%=100;
if(!v[i]&&Notes[i]) v[i]=100,Notes[i]--;
}
for(ll j=1;j<=n;j++) {
scanf("%lld",&c[j]);
}
}
void slv() {
for(ll i=1;i<=n;i++){
que.push(Pair(i,(100-v[i])*c[i]));
m-=v[i];
Coints[i]+=v[i];
while(m<0) {
Pair h=que.top();
que.pop();
m+=100;
Notes[h.x]++;
Coints[h.x]=0;
ang+=h.w;
}
}
}
void print() {
printf("%lld\n",ang);
for(ll i=1;i<=n;i++) printf("%lld %lld\n",Notes[i],Coints[i]);
}
int main() {
readin();
slv();
print();
return 0;
}