Cod sursa(job #2416455)
Utilizator | Carol Luca Carol_Luca | Data | 27 aprilie 2019 16:25:26 |
---|---|---|---|
Problema | Zombie | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.58 kb |
#include <bits/stdc++.h>
#define input "zombie.in"
#define output "zombie.out"
using namespace std;
int d,n,k,a,pos,r,cost;
vector<int> v;
int main()
{
ifstream in(input);
ofstream out(output);
ios_base::sync_with_stdio(false);
in.tie(0),out.tie(0);
in>>d>>n>>k;
for(int i=0;i<n;++i)
in>>a,v.push_back(a);
while(pos<n)
{
r=lower_bound(v.begin()+pos+1,v.end(),v[pos]+d)-v.begin();
--r;
if(r>pos and r-pos+1>=k)
cost+=k,pos=r+1;
else ++cost,++pos;
}
out<<cost;
return 0;
}