結果

問題 No.1148 土偶Ⅲ
ユーザー okazakisteve
提出日時 2020-08-05 17:29:23
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 649 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 79,572 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-17 06:46:58
合計ジャッジ時間 2,082 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream> 
#include <vector>
#include <set>
#include <cstdint> 
using namespace std;

int main() {
  long long int n,w;
  cin >> n >> w;
  vector<long long int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  long long int  res = 0, right = 0, sum = 0;
  set<int> member;
  for (int left = 0; left < n; ++left) {
    while (right < n && !member.count(a[right]) && sum + a[right] <= w) {
      member.insert(a[right]);
      sum += a[right];
      ++right;
    }
    res = max(res, right - left);
    if (left == right) ++right;
    else {
      member.erase(a[left]);
      sum -= a[left];
    }
  }
  cout << res << endl;
  return 0;
}
0