ログイン
新規登録
AtsuoCoder Petrozavodsk Contest 001
読込中…
Home
Tasks
Clar
Submissions
Standings
提出 153d69f7-cab0-4052-a69a-36b852d4d87f
コード
#include<bits/stdc++.h> using namespace std; using ll=long long; const ll inf=1e18; int main(){ cin.tie(0)->sync_with_stdio(0); int n,m; cin>>n>>m; vector<int>I(m),s(m); for(int i=0;i<m;i++) cin>>I[i]; for(int i=0;i<m;i++) cin>>s[i]; deque<int>deq; map<int,int>mp; ll sum=0,ans=inf; int ansl=-1,ansr=-1; for(int r=0;r<m;r++){ deq.push_back(r); mp[I[r]]++; sum+=s[r]; while(mp.size()>=n){ int l=deq.front(); //今考えている区間は閉区間[l,r] //これはdeqに今入っている値 if(sum<ans){ ans=sum; //ここで半開区間に直す ansl=l; ansr=r+1; } deq.pop_front(); mp[I[l]]--; if(mp[I[l]]==0) mp.erase(I[l]); sum-=s[l]; } //「死なない区間」になったタイミングでwhileから出る } if(ansl==-1) cout<<-1<<' '<<-1<<endl; else cout<<ansl+1<<' '<<ansr+1<<endl; }
結果
問題
点数
言語
結果
実行時間
メモリ
F - Sliding
150
C++
AC
185 ms
16040 KiB