結果
問題 |
No.1148 土偶Ⅲ
|
ユーザー |
![]() |
提出日時 | 2020-08-05 17:49:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 70 ms / 2,000 ms |
コード長 | 580 bytes |
コンパイル時間 | 1,429 ms |
コンパイル使用メモリ | 175,036 KB |
実行使用メモリ | 7,552 KB |
最終ジャッジ日時 | 2024-09-17 07:07:16 |
合計ジャッジ時間 | 2,971 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int n, w; cin >> n >> w; vector<int> a(n); for (int i = 0; i < n; i++){ cin >> a[i]; } int ans = 0; long long sum = 0; map<int, int> mp; int R = 0; for (int L = 0; L < n; L++){ while (R < n){ if (sum + a[R] <= w && mp[a[R]] == 0){ sum += a[R]; mp[a[R]]++; R++; } else { break; } } ans = max(ans, R - L); if (R == L){ sum += a[R]; mp[a[R]]++; R++; } sum -= a[L]; mp[a[L]]--; } cout << ans << endl; }