#include #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define RI(X) scanf("%d", &(X)) #define RII(X, Y) scanf("%d%d", &(X), &(Y)) #define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z)) #define DRI(X) int (X); scanf("%d", &X) #define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y) #define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z) #define RS(X) scanf("%s", (X)) #define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0) #define MP make_pair #define PB push_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define PII pair #define VI vector #define VPII vector > #define PLL pair #define VPLL vector > #define F first #define S second typedef long long LL; using namespace std; const int INF = 1e9+7; const int SIZE = 210001; int dp[SIZE],from[SIZE]; VI e[SIZE]; VI gg[SIZE]; int gn; int main(){ { REP(i,SIZE)dp[i]=INF; dp[0]=0; int now=0; for(int i=1;nowdp[j]+i){ dp[j+now]=dp[j]+i; from[j+now]=i; } } now+=i; } } DRII(n,b); DRII(f,c); int need=max(0,max(b,f+n)-n); if(need+c>n*(n-1LL)/2){ puts("-1"); return 0; } int use=-1; for(int i=need;i<=n*(n-1LL)-c&&i