1 solutions

  • 1
    @ 2023-6-9 18:58:17

    由于 XiX_i 太小了,所以可以对于每个点计算在这个点前面所有星星的亮度之和,然后枚举每个长度为 WW 区间就行了,时间复杂度 O(max(Xi))O(\max(X_i))

    #include<bits/stdc++.h>
    using namespace std;
    int f[1000005],sum[1000005],n,m,x,y,ans=-1,maxn=1;
    int main(){
    	cin>>n>>m;
    	for(int i=1;i<=n;i++)cin>>x>>y,f[x]+=y,maxn=max(maxn,x);
    	for(int i=1;i<=maxn;i++)sum[i]=sum[i-1]+f[i];
    	for(int i=1;i<=maxn;i++)ans=max(ans,sum[i]-sum[i-m]);
    	cout<<ans;
    	return 0;
    }
    
    • 1

    Information

    ID
    2454
    Time
    1000ms
    Memory
    125MiB
    Difficulty
    2
    Tags
    # Submissions
    7
    Accepted
    2
    Uploaded By