Ideas:
First two points are found to make X * (x + 1)/2 <= A + b the largest x, then P = min (A, b), q = max (A, b), according to X,x-1, ..., 1 of the order to fill the p, the remaining number of the left not selected in Q.
Realize:
1#include <iostream>2#include <Set>3#include <vector>4 using namespacestd;5 6typedefLong Longll;7 8InlineBOOLCheck (ll X, ll a, ll b)9 {Ten returnX * (x +1) /2<= A +b; One } A - intMain () - { the ll A, B; - while(Cin >> a >>b) - { -ll L =1, r =200000, ans =-1; + while(L <=R) - { +ll m = L + R >>1; A if(Check (M, A, b)) at { -L = m +1; -Ans =m; - } - Else - { inr = M-1; - } to } + Set<int>St; - intx =min (A, b); the for(inti = ans; I >=1; i--) * { $ if(i > x)Continue;Panax Notoginseng St.insert (i); -X-=i; the } + Set<int>St2; A for(inti =1; I <= ans; i++) the { + if(!St.count (i)) st2.insert (i); - } $ if(A >b) Swap (St, st2); $cout << st.size () <<Endl; - for(Auto it:st) cout << it <<" "; -cout <<Endl; thecout << st2.size () <<Endl; - for(Auto It:st2) cout << it <<" ";Wuyicout <<Endl; the } - return 0; Wu}
CF1072C Cram Time