构造题
话说挺水的题。。当时怎么就WA到自闭呢。。
先把每个位置按照最低要求填满,也就是相差1。。然后从最后一位开始把剩下的数加上,直到不能加为止。
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define full(a, b) memset(a, b, sizeof a)
using namespace std;
typedef long long ll;
inline int lowbit(int x){ return x & (-x); }
inline int read(){
int X = 0, w = 0; char ch = 0;
while(!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
while(isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
return w ? -X : X;
}
inline int gcd(int a, int b){ return a % b ? gcd(b, a % b) : b; }
inline int lcm(int a, int b){ return a / gcd(a, b) * b; }
template<typename T>
inline T max(T x, T y, T z){ return max(max(x, y), z); }
template<typename T>
inline T min(T x, T y, T z){ return min(min(x, y), z); }
template<typename A, typename B, typename C>
inline A fpow(A x, B p, C lyd){
A ans = 1;
for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;
return ans;
}
ll a[100005];
int main(){
ll n, k, sum = 0;
cin >> n >> k;
for(int i = 1; i <= k; i ++){
a[i] = i, sum += i;
}
if(sum > n){
printf("NO\n");
}
else{
ll tmp = (n - sum) / k;
if(tmp > 0){
for(int i = 1; i <= k; i ++) a[i] += tmp, sum += tmp;
}
for(int i = k; i >= 1; i --){
int cnt = 0;
while(a[i] < 2 * a[i - 1] && sum < n) a[i] ++, sum ++, cnt ++;
if(!cnt && sum < n){
printf("NO\n");
break;
}
if(sum == n){
printf("YES\n");
for(int j = 1; j <= k; j ++){
cout << a[j];
if(j != k) cout << " ";
}
break;
}
}
}
return 0;
}