結果
問題 | No.935 う し た ぷ に き あ く ん 笑 ビ - ム |
ユーザー |
|
提出日時 | 2020-04-21 22:34:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 12 ms / 2,000 ms |
コード長 | 1,066 bytes |
コンパイル時間 | 844 ms |
コンパイル使用メモリ | 77,836 KB |
最終ジャッジ日時 | 2025-01-09 22:11:23 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 58 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <string> using lint = long long; constexpr lint INF = 1LL << 60; void solve() { int n; std::string s; std::cin >> n >> s; std::vector<lint> xs(n); for (auto& x : xs) std::cin >> x; std::vector<lint> need(n + 1, INF); need[0] = 0; for (int q = 0; q < 2; ++q) { for (int l = 0; l < n; ++l) { int cnt = 0; lint cost = 0; for (int i = l; i < n; ++i) { if (s[i] == 'E') ++cnt; cost += xs[i]; need[cnt] = std::min(need[cnt], cost); } } std::reverse(s.begin(), s.end()); std::reverse(xs.begin(), xs.end()); } int q; std::cin >> q; while (q--) { lint k; std::cin >> k; std::cout << std::upper_bound(need.begin(), need.end(), k) - need.begin() - 1 << std::endl; } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }