vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; }
vector<int> b(a); sort(b.begin(), b.end());
vector<int> pre(n + 1); for (int i = 0; i < n; i++) { pre[i + 1] += pre[i] + b[i]; }
int ans = n + 1; for (int i = 1; i <= n; i++) { if (m >= pre[i]) { ans = min(ans, n - i + 1); } if (i < n and m >= pre[i] + max(0, a[i] - b[i - 1])) { ans = min(ans, n - i); } } cout << ans << "\n"; }
constexprint MOD = 998244353; constexprint M = 300 * 300;
intnorm(int x){ if (x < 0) { x += MOD; } if (x >= MOD) { x -= MOD; } return x; } template<class T> T binpow(T a, int b){ T res = 1; for (; b; b /= 2, a *= a) { if (b % 2) { res *= a; } } return res; }
structZ { int x; Z(int x = 0) : x(norm(x)) {} intval()const{ return x; } Z operator-() const { returnZ(norm(MOD - x)); } Z inv()const{ assert(x != 0); returnbinpow(*this, MOD - 2); } Z &operator*=(const Z &rhs) { x = 1LL * x * rhs.x % MOD; return *this; } Z &operator+=(const Z &rhs) { x = norm(x + rhs.x); return *this; } Z &operator-=(const Z &rhs) { x = norm(x - rhs.x); return *this; } Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); } friend Z operator*(const Z &lhs, const Z &rhs) { Z res = lhs; res *= rhs; return res; } friend Z operator+(const Z &lhs, const Z &rhs) { Z res = lhs; res += rhs; return res; } friend Z operator-(const Z &lhs, const Z &rhs) { Z res = lhs; res -= rhs; return res; } friend Z operator/(const Z &lhs, const Z &rhs) { Z res = lhs; res /= rhs; return res; } };
vector<int> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i];; }
vector<int> d(n + 1); for (int i = 0; i < n; i++) { if (a[i] > b[i]) { ++d[b[i]]; --d[a[i]]; } }
for (int i = 1; i <= n; i++) { d[i] += d[i - 1]; }
vector<int> ans; for (int k = 1; k <= n; k++) { int ok = 1; for (int i = k; i <= n; i += k) { if (d[i]) { ok = 0; break; } } if (ok) ans.push_back(k); }
cout << ans.size() << "\n"; for (auto x : ans) { cout << x << " \n"[x == ans.back()]; } }
return0; }
Educational Codeforces Round 141 (Rated for Div. 2)【A - E】