0%

2025“钉耙编程”中国大学生算法设计暑期联赛(5)——"合理"避税

思路讲解

核心就是知道可以发多少个月,就可以知道总共可以发多少个人次,一个人最多可以发多少钱。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
auto check=[&](ll mid){
// 我们一共可以给mid*P个人次发钱。
ll chance=mid*P;
vpll rem;
ll ans=0;
FOR(i,1,N){
ll a=A[i-1];
ll ci=min({a/K,mid,chance});
chance-=ci;
ans+=ci*K;
ll r=a-K*ci;
if(r>0) rem.EB(r,mid-ci);
}
if(chance<=0){
if(ans>=M){
return true;
}else{
return false;
}
}
sort(all(rem),greater<>());
for(auto [v,ci]:rem){
if(chance==0) break;
if(ci>0) ans+=v,chance--;
}
if(ans>=M){
return true;
}else{
return false;
}
};

AC代码

https://acm.hdu.edu.cn/contest/view-code?cid=1176&rid=8395

心路历程(WA,TLE,MLE……)