voidsolve(){ int N, X; cin >> N >> X; N -= 1; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int Y = 0; Y <= X; Y++) { auto B = A; B.pb(Y); debug(B); sort(all(B)); int S = 0; for (int i = 1; i < N; i++) { S += B[i]; } debug(S, X); if (S >= X) { cout << Y << "\n"; return; } } cout << -1 << "\n"; }
voidsolve(){ int N, M, K; cin >> N >> M >> K; vi a(N), b(M); read(a, b); vector<longlong> B(M + 1); sort(all(b)); B[0] = 0; for (int i = 0; i < M; i++) { B[i + 1] = B[i] + b[i]; }
ll ans = 0; for (int i = 0; i < N; i++) { int p = lower_bound(all(b), K - a[i]) - b.begin(); ans += 1ll * a[i] * p + B[p] + 1ll * K * (M - p); }
voidsolve(){ int N, M; cin >> N >> M; vector<int> R(M), B(M); for (int i = 0; i < M; i++) { cin >> R[i]; --R[i]; } for (int i = 0; i < M; i++) { cin >> B[i]; --B[i]; } vector<longlong> inv(M + 1); inv[1] = 1; for (int i = 2; i <= M; i++) { inv[i] = P - inv[P % i] * (P / i) % P; } vector<longlong> fact(M + 1), invf(M + 1); fact[0] = invf[0] = 1; for (int i = 1; i <= M; i++) { fact[i] = fact[i - 1] * i % P; invf[i] = invf[i - 1] * inv[i] % P; }
vector<int> X(N, 0); vector<int> Y(N, 0); for (int i = 0; i < M; i++) { X[R[i]] += 1; Y[B[i]] += 1; }
vector<int> SX(1 << N, 0), SY(1 << N, 0); for (int i = 0; i < 1 << N; i++) { for (int j = 0; j < N; j++) { if (i >> j & 1) { SX[i] += X[j]; SY[i] += Y[j]; } } }