Cod sursa(job #343767)
| Utilizator | Data | 27 august 2009 11:24:11 | |
|---|---|---|---|
| Problema | Orase | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.47 kb |
#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;}
