【Codeforces 1031C】Cram Time
【链接】 我是链接,点我呀:)
【题意】
【题解】
如果找到最大的n使得1+2+...+n<=a+b 然后第一天输出1,2.3,4....t1 这里1+2+..+t1<=a 这还远远不够。 因为可能1+2+3...+t1【代码】
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5;
ll a,b;
ll n;
int tag[N+10];
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> a >> b;
//(1+n)*n/2
for (n = 0;n*(1+n)/2<=(a+b);n++);
n--;
ll t1 = 0;
for (t1 = 1;t1*(t1+1)/2<=a;t1++);
t1--;
if (t1*(t1+1)/2==a){
cout<<t1<<endl;
for (ll i = 1;i <= t1;i++){
cout<<i<<" ";
}
cout<<endl;
cout<<n-t1<<endl;
for (ll i = t1+1;i <= n;i++){
cout<<i<<" ";
}
}else{
t1++;
ll temp = t1*(t1+1)/2-a;
cout<<t1-1<<endl;
int cnt = 0;
for (ll i = 1;i <= t1;i++)
if (i!=temp){
cout<<i<<" ";
cnt++;
}
if (cnt>0) cout<<endl;
cout<<n-(t1-1)<<endl;
if (n-(t1-1)>0)cout<<temp<<" ";
for (ll i = t1+1;i <= n;i++){
cout<<i<<" ";
}
}
return 0;
}