結果
| 問題 | No.935 う し た ぷ に き あ く ん 笑 ビ - ム | 
| コンテスト | |
| ユーザー |  tkmst201 | 
| 提出日時 | 2019-11-29 22:23:57 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 15 ms / 2,000 ms | 
| コード長 | 1,322 bytes | 
| コンパイル時間 | 1,649 ms | 
| コンパイル使用メモリ | 173,180 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-14 05:48:19 | 
| 合計ジャッジ時間 | 3,472 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge6 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 58 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//
int N, Q;
string S;
int A[2123], K[2123];
int mxpos[2123];
ll sum[2123], cnt[2123]; // 1-indexed
int ans[2123];
int main() {
	cin >> N >> S;
	REP(i, N) scanf("%d", A + i);
	cin >> Q;
	REP(i, Q) scanf("%d", K + i);
	
	vector<int> ord(Q);
	iota(ALL(ord), 0);
	
	sort(ALL(ord), [&](int x, int y) {
		return K[x] < K[y];
	});
	
	REP(i, N) {
		sum[i + 1] = sum[i] + A[i];
		cnt[i + 1] = cnt[i] + (S[i] == 'E');
	}
	
	iota(mxpos, mxpos + N, 0);
	
	int mx = 0;
	for (int curq : ord) {
		// K[curq]までいける
		REP(i, N) {
			int cur = mxpos[i];
			while (cur < N && sum[cur + 1] - sum[i] <= K[curq]) cur++;
			mxpos[i] = cur;
			chmax(ans[curq], cnt[cur] - cnt[i]);
		}
	}
	
	REP(i, Q) printf("%d\n", ans[i]);
	
	return 0;
}
            
            
            
        