P3353 the stars shining outside your window

Source: Internet
Author: User

Huang question upset how to do online wait very urgent ah ...

I read the subject in earnest.

I cried, what about you?

One punch, one tear-eye freak.

This question looks like a prefix and one at a glance. Then I was in the mood to write a dash, handed up 10pt,wa sound a piece.

The original idea was mentally retarded, and I thought the stars he gave were given in ascending order of X.

And one more thing: the stars may overlap. A point may have more than one star. That's all I'm not thinking about.

So what's the best way?

Open a B-array directly, recording the brightness of the stars for each x-coordinate.

If asked, first preprocess the prefix and then the \ (n\) ( O (1) \) query. Complexity \ (O (n) \).

Code:

#include<cstdio>#include<algorithm>const int maxn = 100005;int maxx;int b[maxn];int n, w;int main(){    scanf("%d%d", &n, &w);    for(int i = 1; i <= n; i++)    {        int xx, bb; scanf("%d%d", &xx, &bb);        b[xx] += bb;        maxx = std::max(maxx, xx);    }    for(int i = 1; i <= maxx; i++) b[i] += b[i - 1];    int ans = -19260817;    for(int i = 1; i + w - 1 <= maxx; i++)    {        ans = std::max(ans, b[i + w - 1] - b[i - 1]);    }    printf("%d\n", ans);    return 0;}

P3353 the stars shining outside your window

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.