【洛谷3353】在你窗外闪耀的星星(前缀和)

题面

原题

Solution

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<queue>
#define ll long long
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;
inline int gi(){
    int sum=0,f=1;char ch=getchar();
    while(ch>'9' || ch<'0'){if(ch=='-')f=-f;ch=getchar();}
    while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return f*sum;
}
inline ll gl(){
    ll sum=0,f=1;char ch=getchar();
    while(ch>'9' || ch<'0'){if(ch=='-')f=-f;ch=getchar();}
    while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return f*sum;
}
int a[100010],sum[100010];
int main(){
    int i,j,n,m,k,w;
    n=gi();w=gi();
    for(i=1;i<=n;i++){
        int x=gi(),b=gi();
        a[x]+=b;
    }
    for(i=1;i<=100000;i++)
        sum[i]=sum[i-1]+a[i];
    int ans=0;
    for(i=1;i<=100000-w;i++)
        ans=max(ans,sum[i+w]-sum[i]);
    printf("%d\n",ans);
    return 0;
}
posted @ 2018-10-28 22:21  cj_gjh  阅读(184)  评论(0编辑  收藏  举报