fork(28) download
  1. #include<iostream>
  2. #include<math.h>
  3. #include<algorithm>
  4. #include<stdio.h>
  5. #include<map>
  6. #include<vector>
  7. #include<set>
  8. #include<iomanip>
  9. #define F first
  10. #define S second
  11. #define P system("PAUSE");
  12. #define H return 0;
  13. #define pb push_back
  14. using namespace std;
  15. const long long A=100000000000000LL,N=228228;
  16.  
  17. char e[21];
  18. vector<string> ot;
  19. pair<int,pair<int,string> > a[N];
  20. long long o,p[3]={-1,-1,-1};
  21. int i,j,l,r,n,m;
  22.  
  23. int main(){
  24. cin>>n>>m;
  25. for(i=0;i<n;++i){
  26. scanf("%d%d",&a[i].F,&a[i].S.F);
  27. a[i].S.S=e;
  28. }
  29. sort(a,a+n);
  30. for(l=0;l<n;o-=a[l].S.F,++l){
  31. while(r<n && abs(a[l].F-a[r].F)<m)o+=a[r].S.F,++r;
  32. if(o>=p[0])p[0]=o,p[1]=l,p[2]=r;
  33. }
  34. for(i=p[1];i<p[2];++i)ot.pb(a[i].S.S);
  35. cout<<p[0]<<"\n";
  36. }
Success #stdin #stdout 0s 6140KB
stdin
Standard input is empty
stdout
-1