結果
| 問題 |
No.935 う し た ぷ に き あ く ん 笑 ビ - ム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-11-29 22:02:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 2,000 ms |
| コード長 | 924 bytes |
| コンパイル時間 | 1,507 ms |
| コンパイル使用メモリ | 170,328 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-14 05:42:46 |
| 合計ジャッジ時間 | 3,483 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 58 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
string s;
cin >> s;
vector<ll> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
auto solve = [&](ll K) -> int {
ll sum = 0;
int ans = 0, cnt = 0;
for (int i = 0, j = 0; i < n; i++) {
while (j < n) {
if (sum + a[j] > K) break;
sum += a[j];
cnt += (s[j] == 'E');
j++;
}
ans = max(ans, cnt);
if (i == j) {
j++;
continue;
}
cnt -= (s[i] == 'E');
sum -= a[i];
}
return ans;
};
int q;
cin >> q;
for (int i = 0; i < q; i++) {
ll K;
cin >> K;
cout << solve(K) << "\n";
}
return 0;
}