Cod sursa(job #694087)

Utilizator cashinmypocketAndrei Mihu cashinmypocket Data 27 februarie 2012 18:38:01
Problema Lupul Urias si Rau Scor 4
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
long long n,l,x,i,q[10000],maxi,s;
struct oaie { int d,c;
			} v[100000];
int fcomp(const void *x,const void *y)
{ oaie a=*(oaie *)x;
  oaie b=*(oaie *)y;
  if(b.d-a.d) return b.d-a.d;
  return b.c-a.c;
}
int main()
{ f>>n>>x>>l;
  for(i=1;i<=n;i++) f>>v[i].d>>v[i].c;
  qsort(v+1,n,sizeof(oaie),fcomp);
  for(i=1;i<=n;i++) q[i]=(x-v[i].d)/l+1;
  maxi=v[1].c;
  for(i=2;i<=n;i++) if(q[i]==q[i-1]&&v[i].c>maxi) maxi=v[i].c;
					else if(q[i]!=q[i-1]) { s+=maxi;
                                            maxi=v[i].c;
										  }
  s+=maxi;
  g<<s<<"\n";
  f.close();
  g.close();
  return 0;  
}