Pagini recente » Cod sursa (job #2167966) | Cod sursa (job #1360966) | Cod sursa (job #2932693) | Istoria paginii lot-2017/baraj-3/clasament | Cod sursa (job #636006)
Cod sursa(job #636006)
#include <fstream>
using namespace std;
int main()
{
ifstream f("zombie.in");
ofstream g("zombie.out");
int n,d,k,x,i;
int seq_start,seq_length,total;
f>>d>>n>>k;
//ini
f>>seq_start; //first seq start is the enter of the first zombie
seq_length = 1;//first seq is the first zombie
total = 0;
d--;
for (i=1;i<n;i++)
{
f>>x;
if ((x-seq_start)<d) //more zombies can enter the aley
seq_length ++;
else
{
if (seq_length>k)
total += k;
else
total += seq_length;
seq_start = x; //reset the sequence
seq_length = 1; //reset the length
}
}
//add the last sequence
if (seq_length>k)
total += k;
else
total += seq_length;
//print the rezult
g<<total<<"\n";
f.close();
g.close();
return 0;
}