Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

#include <iostream>

#include <fstream>
using namespace std;

ifstream fin("cerc3.in");
ofstream fout("cerc3.out");
int n;

struct cerc {
int start, stop;
} v[310];

void citire( cerc v[] , int &n)


{
int x,y,i;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>x;
cin>>y;
v[i].start= x-y;
v[i].stop= x+y;
}
}

void ordonare(cerc v[], int n)


{
int ok=1, i;
while(ok!=0)
{
ok=0;
for(i=1;i<n;i++)
{
if(v[i].start> v[i+1].start)
{
v[0]=v[i];
v[i]=v[i+1];
v[i+1]=v[0];
ok=1;
}

}
}
}

void greedy(cerc v[] , int n)


{
int i,p,nr=1;
p=v[1].stop;

for(i=2;i<=n;i++)
{
if(v[i].start> p)
{
nr++;
p=v[i].stop;
}
}
cout<<nr;
}
int main()
{
citire(v,n);
ordonare(v,n);
greedy(v,n);
return 0;
}

You might also like