結果

問題 No.935 う し た ぷ に き あ く ん 笑 ビ - ム
ユーザー k
提出日時 2020-07-23 23:06:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 2,380 ms
コンパイル使用メモリ 194,348 KB
最終ジャッジ日時 2025-01-12 04:39:32
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 58
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a(n);
  REP (i, n) cin >> a[i];
  int q;
  cin >> q;

  while (q--) {
    long long k;
    cin >> k;
    long long acc = 0;
    int ret = 0;
    int cnt = 0;
    for (int i = 0, j = 0; i < n; i++) {
      j = max(j, i);
      while (j < n && acc + a[j] <= k) {
        acc += a[j];
        if (s[j] == 'E')
          ++cnt;
        ++j;
      }
      
      ret = max(ret, cnt);
      if (i < j) {
        acc -= a[i];
        if (s[i] == 'E')
          --cnt;
      }
    }
      
    cout << ret << endl;
  }

  return 0;
}
0