[3353] Luo Gu in your window shining star

Title Description

Fleeting time will not blur my memory of you. Hard to believe that from the first time I saw you three years have passed since. I also still vividly remember three years ago, in the beautiful Jimei school, I see you smile from out of the classroom, you will head back, soft sunset shining on your rosy cheeks. I know, I've been indulging in you. Later, after several months of observation and spy, your grace and wisdom, your attitude towards life and you deeply impressed on my mind for the future aspirations. You are charming sun girl, I always dreamed to share with you the rest. Well, actually you far beyond my wildest dreams. I do not know how to play bridge the gap between me and you. So I do not have any plans, just waiting, waiting for an appropriate opportunity comes. Until now, the arrival of graduation, I realized that I'm an idiot, I should create the opportunity and grab it instead of just waiting.

These days, I and my friends, roommates, classmates one by one separately. I still can not believe, after the wave, these familiar faces will soon disappear from our lives, leaving only memories. I will be out of school tomorrow. You have planned to run away, pursue your future and achieve your dreams. If there is no fate, maybe we will not meet again. So tonight, I'm your dorm wandering downstairs, hoping to chance to meet you. But, paradoxically, your looks will make my heart beat faster, my clumsy tongue may not spit out a word. I do not remember how many times you go through the dormitory, every time you want to see appear on the balcony or on the windowsill. I do not remember how many times had this idea in my mind gushed: to call her to dinner or a chat. But each time, taking into account your excellent and my ordinary, timid advantage over courage drove me to quietly leave.

Graduation, high school means the end of life. End of these glorious and romantic era. Your lovely smile is my original study hard, this unrequited love will be sealed, as a memory of my soul. Graduation, it means the beginning of a new life, to reach a bright future footprint. I wish you happy every day in a foreign country, all the best. At the same time, I will try to come out from the naive to become more mature. My ideal would be to pursue my love and happiness in the real world, I will never give up.

Good-bye, my princess!

If one day, at some ends of the earth, we have the opportunity to meet, even the white-haired men and women, at that time, I hope we can be good friends to proud to share this memory, reliving happy young passion. If this opportunity never comes, I hope I am the stars in the sky, flashing in your window. Far bless you, like a friend to accompany you around every night, sweet dreams also to share or experience with terrible dream.

Now the question is: will be appreciated that the sky as a number of axes, the number of axes in this distribution of many stars, each star for the position Xi has its own brightness and Bi. The windows can see the range parameter W is a given, we see the stars, including stars window edge. Now, after you obtained to adjust the position of the window to see the sum of the maximum brightness of the stars.

Input and output formats

Input formats:

 

Width line N, W, representing the number of stars and windows

The remaining N rows, and input Xi Bi, representative of the coordinates and brightness of stars

 

Output formats:

 

A number that represents the maximum brightness can see the stars and

 

Sample input and output

Input Sample # 1:  Copy
6 3
1 2
2 4
3 8
4 4
5 2
1000 1
Output Sample # 1:  Copy
16

Explanation

Sample Description:

For 10% of the data, W = 0 (no edge)

Data for 40%, W <= 1000

To 100% of the data, N <= 100000, W <= 100000, Xi <= 100000,1 <= Bi <= 100

In addition to W = 0, W are> 3 = odd number

 

Solution: I'm sorry I was a rough Han sweet to! Science students love could be so romantic.

//在你窗外闪耀的星星
#include<iostream>
#include<cstdio>
using namespace std;

const int MAXN = 100000 + 1;

int n, w;
int tree[MAXN << 2];

void Update(int o, int l, int r, int p, int v) {
    if(l == r) tree[o] += v;
    else {
        int mid = (l + r) >> 1;
        if(l <= p && p <= mid) Update(o << 1, l, mid, p, v);
        else Update(o << 1|1, mid + 1, r, p, v);
        tree[o] = tree[o << 1] + tree[o << 1|1];
    }
}
long long Query(int o, int l, int r, int ql, int qr) {
    if(ql <= l && r <= qr) return tree[o];
    int mid = (l + r) >> 1;
    long long ret = 0;
    if(ql <= mid) ret += Query(o << 1, l, mid, ql, qr);
    if(qr > mid) ret += Query(o << 1|1, mid + 1, r, ql, qr);
    return ret;
}
int main() {
    scanf("%d%d", &n, &w);
    if(w == 0) { puts("0"); return 0; }
    for(int i = 1; i <= n; ++i) {
        int pos, num;
        scanf("%d%d", &pos, &num);
        Update(1, 1, n, pos, num);
    }
    long long ans = 0;
    for(int i = 1, j = w; j <= n; ++i, ++j) {
        ans = max(ans, Query(1, 1, n, i, j));
    }
    printf("%lld\n", ans);
}

 

Guess you like

Origin www.cnblogs.com/wuhu-JJJ/p/11204491.html