結果
| 問題 | No.935 う し た ぷ に き あ く ん 笑 ビ - ム | 
| コンテスト | |
| ユーザー |  r1933 | 
| 提出日時 | 2019-11-29 22:33:54 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 24 ms / 2,000 ms | 
| コード長 | 1,635 bytes | 
| コンパイル時間 | 1,869 ms | 
| コンパイル使用メモリ | 170,620 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-14 05:50:00 | 
| 合計ジャッジ時間 | 3,780 ms | 
| ジャッジサーバーID (参考情報) | judge6 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 58 | 
ソースコード
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
// Begin {{{
using namespace std;
#ifndef DEBUG
#define dump(...)
#endif
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}
template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}
constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    size_t N; cin >> N;
    string s; cin >> s;
    vector<intmax_t> cum(N + 1);
    for (size_t i = 1; i <= N; ++i) {
        cum[i] = cum[i - 1] + (s[i - 1] == 'E');
    }
    vector<intmax_t> a(N + 1);
    for (size_t i = 1; i <= N; ++i) {
        cin >> a[i];
    }
    size_t Q; cin >> Q;
    while (Q--) {
        size_t K; cin >> K;
        intmax_t maxv = 0;
        int right = 1, sum = 0;
        for (int left = 1; left <= N; ++left) {
            while (right <= N && sum + a[right] <= K) {
                sum += a[right];
                right++;
            }
            chmax(maxv, cum[right - 1] - cum[left - 1]);
            if (right == left) {
                right++;
            } else {
                sum -= a[left];
            }
        }
        cout << maxv << "\n";
    }
    return 0;
}
            
            
            
        