#include #pragma GCC optimize("O3") using namespace std; using ll = long long; #define rep(i,n) for (int i = 0; i < (n); ++i) #define rep2(i,m,n) for (int i = (m); i < (n); ++i) #define rep3(i,a,b) for (int i = (a); i >= (b); --i) #define all(x) (x).begin(),(x).end() inline int popcount(const int x) { return __builtin_popcount(x);} inline ll popcount(const ll x) { return __builtin_popcountll(x);} template void chmin(T &a, const T &b) noexcept { if (b < a) a = b;} template void chmax(T &a, const T &b) noexcept { if (a < b) a = b;} template void drop(const T &x) { std::cout< void debug_out(const T &x, const Args &... args) { std::cout<> n >> s; vector a(n), SE(n+1), SP(n+1); //enemy, MP rep(i,n) { SE[i+1] += SE[i]; if (s[i] == 'E') SE[i+1]++; } rep(i,n) { cin >> a[i]; SP[i+1] += SP[i] + a[i]; } vector dp(n+5, INF); //j体倒すのに必要な最小MP dp[0] = 0; rep(i,n) { //iから放つ rep2(j, 1, n+1) { int k = lower_bound(all(SE), j + SE[i]) - SE.begin(); if (k >= n+1) break; // debug(i, j, k, SP[k] - SP[i]); chmin(dp[j], SP[k] - SP[i]); } } int q; cin >> q; while(q--) { ll k; cin >> k; int ans = 0; rep(i, n+1) { if (dp[i] <= k) ans = i; else break; } cout << ans << "\n"; } return 0; }