Pagini recente » Cod sursa (job #2939570) | Cod sursa (job #456155) | Cod sursa (job #2154059) | Cod sursa (job #2166036) | Cod sursa (job #636441)
Cod sursa(job #636441)
#include<iostream>
#include<fstream>
#define maxn 1000005
using namespace std;
long T[maxn],Best[maxn],i,s,n,d,k,dr;
int main()
{
ifstream in("zombie.in");
ofstream out("zombie.out");
in>>d>>n>>k;
for ( i=1; i<=n; ++i)
in>>T[i];
n++;
T[n]=1000000002;
for ( s=1; s<=n; ++s)
{
while ( T[s]+d-1>=T[dr] && dr<=n+1)
{
dr++;
// cout<<T[s]+d-1<<" "<<T[dr]<<" "<<dr<<"\n";
}
dr--;
//out<<dr<<"@\n";
if ( Best[dr+1]>Best[s]+k || Best[d+1]==0)
Best[dr+1]=Best[s]+k;
if ( Best[s+1]>Best[s]+1 || Best[s+1]==0)
Best[s+1]=Best[s]+1;
}
out<<Best[n]<<"\n";
return 0;
}