A. Santa Claus and Candies
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Santa Claus has n candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all n candies he has.
Input
The only line contains positive integer number n (1 ≤ n ≤ 1000) — number of candies Santa Claus has.
Output
Print to the first line integer number k — maximal number of kids which can get candies.
Print to the second line k distinct integer numbers: number of candies for each of k kid. The sum of k printed numbers should be exactly n.
If there are many solutions, print any of them.
Examples
input
5
output
2
2 3
input
9
output
3
3 5 1
input
2
output
1
2
题意
有n个糖果,最多可以分给k个人,每个人分得的糖数不同,求k和每个人的糖数
/*************************************************************************
> File Name: cf753a.cpp
> Author:ukiy
> Mail:
> Created Time: 2017年01月05日 星期四 00时52分15秒
************************************************************************/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<map>
#include<queue>
#define rep(i,a,b) for(int i=(a);i<=(b);(i++))
#define inf 0x3f3f3f
#define ll long long
#define pi acos(-1)
int dire[4][2]={ {0,1},{1,0},{0,-1},{-1,0} };
int dire2[8][2]={{-1,-1},{-1,0},{-1,1},{ 0,-1},{ 0,1},{ 1,-1},{ 1,0},{ 1,1}};
int dire3[6][3]={ {0,0,1},{0,1,0},{1,0,0},{0,0,-1},{0,-1,0},{-1,0,0} };
using namespace std;
int a[100];
int main()
{
std::ios::sync_with_stdio(false);
//freopen("in.txt","r",stdin);
int n;
cin>>n;
int cnt=0;
for(int i=1;i<=n;i++){
cnt++;
n-=i;
a[i]=i;
}
a[cnt]+=n;
printf("%d\n",cnt);
rep(i,1,cnt-1){
printf("%d ",a[i]);
}
printf("%d\n",a[cnt]);
return 0;
}