結果
| 問題 | 
                            No.1148 土偶Ⅲ
                             | 
                    
| ユーザー | 
                             SSRS
                         | 
                    
| 提出日時 | 2020-08-05 17:51:06 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 70 ms / 2,000 ms | 
| コード長 | 721 bytes | 
| コンパイル時間 | 1,695 ms | 
| コンパイル使用メモリ | 175,408 KB | 
| 実行使用メモリ | 7,448 KB | 
| 最終ジャッジ日時 | 2024-09-17 07:08:54 | 
| 合計ジャッジ時間 | 2,913 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, w;
  cin >> n >> w;
  assert(1 <= n);
  assert(n <= 100000);
  assert(0 <= w);
  assert(w <= 1000000000);
  vector<int> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
    assert(0 <= a[i]);
    assert(a[i] <= 1000000000);
  }
  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;
}
            
            
            
        
            
SSRS