結果
問題 |
No.1148 土偶Ⅲ
|
ユーザー |
|
提出日時 | 2020-08-22 05:05:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 834 bytes |
コンパイル時間 | 788 ms |
コンパイル使用メモリ | 99,276 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 06:44:33 |
合計ジャッジ時間 | 2,016 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <stdio.h> #include <queue> #include <deque> #include <cstdio> #include <set> #include <map> #include <bitset> #include <stack> #include <cctype> using namespace std; long long a[100010]; int main() { long long n, k; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } long long ans = 0; int right = 0; long long sum = 0; set<long long>st; int s = 0; for (int left = 0; left < n; left++) { while (right < n && !st.count(a[right]) && sum + a[right] <= k) { sum += a[right]; st.insert(a[right]); right++; } if (ans < right - left) { ans = right - left; } if (left == right) { right++; } else { st.erase(a[left]); sum -= a[left]; } } cout << ans << endl; }