Submission #884402

#TimeUsernameProblemLanguageResultExecution timeMemory
884402lalig777Telefoni (COCI17_telefoni)C++14
80 / 80
45 ms1624 KiB
#include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; int main(){ int n, d; cin>>n>>d; vector<int>telefoni(n); priority_queue<pair<int,int>, vector<pair<int, int> >, greater<pair<int,int> > >pq; pq.push(make_pair(0, 0)); cin>>telefoni[0]; telefoni[0]=0; for (int i=1; i<n; i++){ cin>>telefoni[i]; if (telefoni[i]==0) telefoni[i]=1; else telefoni[i]=0; while (!pq.empty()){ if (i-pq.top().second>d) pq.pop(); else{ telefoni[i]+=pq.top().first; pq.push(make_pair(telefoni[i], i)); break; } } }cout<<telefoni[n-1]<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...