結果

問題 No.1148 土偶Ⅲ
ユーザー
提出日時 2020-08-22 04:48:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 887 bytes
コンパイル時間 853 ms
コンパイル使用メモリ 100,296 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-15 06:43:57
合計ジャッジ時間 3,046 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 && sum + a[right] < k) {
			if (!st.empty()) {
				s = st.size();
			}
			st.insert(a[right]);
			if (s == st.size()) {
				break;
			}
			sum += 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;
}
0