Pagini recente » Cod sursa (job #628548) | Cod sursa (job #1048034) | Cod sursa (job #2362234) | Cod sursa (job #1892569) | Cod sursa (job #343767)
Cod sursa(job #343767)
#include<fstream>
using namespace std;
ifstream in("orase.in");
ofstream out("orase.out");
int main()
{int m,n,x,d[50001],dist[50001],pozmin,pozmax;
in>>m>>n;
in>>d[1]>>x; dist[1]=d[1]+x;int max=dist[1],min=dist[1];
for(int i=2;i<=n;i++) {in>>d[i]>>x; dist[i]=d[i]+x;if(dist[i]>max) {max=dist[i];pozmax=i;} if(dist[i]<min) {min=dist[i];pozmin=i;}}
if(d[pozmax]<d[pozmin]) out<<max+min-2*d[pozmax]+2;
else out<<max+min-2*d[pozmin]+2;
return 0;}