Codeforces Round #321 (Div. 2) b. Kefa and Company

Source: Internet
Author: User
Tags define local

After sorting o (n) enumerates the tails. The head is monotonous, maintenance is good.

#include <bits/stdc++.h>using namespaceStd;typedefLong Longll;//#define LOCALConst intMAXN = 1e5+5;structnode{intm,s; voidIn () {scanf ("%d%d",&m,&s); }    BOOL operator< (ConstNODE&AMP;RH)Const {        returnM <RH.M; }}nd[maxn];ll SS[MAXN];intMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endif    intN,d; scanf"%d%d",&n,&d);  for(inti =1; I <= N; i++) {Nd[i].    In (); } sort (nd+1, nd+1+N);  for(inti =1; I <= N; i++) {Ss[i]= ss[i-1]+Nd[i].s; } ll ans=0;  for(inti =1, j =1; I <= N; i++){         while(J<n && nd[j+1].M-ND[I].M < D) J + +; Ans= Max (ans,ss[j]-ss[i-1]); } printf ("%i64d", ans); return 0;}

Codeforces Round #321 (Div. 2) b. Kefa and Company

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.