CF1157D N Problems During K Days
思路
简单的贪心
序列肯定是由几段公差为1的等差数列组成的,然后之间计算剩下的数字能有多大的和,不够的话整体上升1补上就好了
代码
#include <cstdio>
#include <algorithm>
#include <cstring>
#define int long long
using namespace std;
int n,k,last=0,a[101000];
int sum(int first,int times){
return (first+times-1+first)*times/2;
}
signed main(){
scanf("%d %d",&n,&k);
for(int i=1;i<=k;i++){
int q=last+1,t=k-i+1;
int delta=max(n-sum(q,t),0LL);
if(i!=1)
q+=min(last-1,delta/t);
else
q+=delta/t;
n-=q;
last=q;
a[i]=q;
}
if(n!=0)
printf("NO\n");
else{
printf("YES\n");
for(int i=1;i<=k;i++)
printf("%d ",a[i]);
printf("\n");
}
return 0;
}