結果
問題 |
No.1148 土偶Ⅲ
|
ユーザー |
|
提出日時 | 2020-08-20 22:01:08 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 82 ms / 2,000 ms |
コード長 | 893 bytes |
コンパイル時間 | 1,625 ms |
コンパイル使用メモリ | 165,904 KB |
実行使用メモリ | 9,216 KB |
最終ジャッジ日時 | 2024-10-13 18:04:51 |
合計ジャッジ時間 | 3,968 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> #define ft first #define sc second #define pt(sth) cout << sth << "\n" using namespace std; typedef long long ll; typedef pair<ll, ll> pll; template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;} template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;} static const ll INF=1e18; static const ll MAX=101010; static const ll MOD=998244353; //for(i=0; i<N; i++) cin >> a[i]; int main(void) { ll i, j, k; ll N, W; cin >> N >> W; ll a[MAX]; for(i=0; i<N; i++) cin >> a[i]; map<ll, ll> use; ll r=0; ll ans=0; ll S=0; for(ll l=0; l<N; l++) { while(r<N && !use[a[r]] && S+a[r]<=W) { S+=a[r]; use[a[r]]=1; r++; } chmax(ans, r-l); if(l==r) r++; else { S-=a[l]; use[a[l]]=0; } } pt(ans); }