Sicily 1092. Stars in Your Window

1092. Stars in Your Window

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

Fleeting time does not blur my memory of you. Can it really be 4 years since I first saw you? I still remember, vividly, on the beautiful Zhuhai Campus, 4 years ago, from the moment I saw you smile, as you were walking out of the classroom and turned your head back, with the soft sunset glow shining on your rosy cheek, I knew, I knew that I was already drunk on you. Then, after several months’ observation and prying, your grace and your wisdom, your attitude to life and your aspiration for future were all strongly impressed on my memory. You were the glamorous and sunny girl whom I always dream of to share the rest of my life with. Alas, actually you were far beyond my wildest dreams and I had no idea about how to bridge that gulf between you and me. So I schemed nothing but to wait, to wait for an appropriate opportunity. Till now — the arrival of graduation, I realize I am such an idiot that one should create the opportunity and seize it instead of just waiting.

 These days, having parted with friends, roommates and classmates one after another, I still cannot believe the fact that after waving hands, these familiar faces will soon vanish from our life and become no more than a memory. I will move out from school tomorrow. And you are planning to fly far far away, to pursue your future and fulfill your dreams. Perhaps we will not meet each other any more if without fate and luck. So tonight, I was wandering around your dormitory building hoping to meet you there by chance. But contradictorily, your appearance must quicken my heartbeat and my clumsy tongue might be not able to belch out a word. I cannot remember how many times I have passed your dormitory building both in Zhuhai and Guangzhou , and each time aspired to see you appear in the balcony or your silhouette that cast on the window. I cannot remember how many times this idea comes to my mind: call her out to have dinner or at least a conversation. But each time, thinking of your excellence and my commonness, the predominance of timidity over courage drove me leave silently.

 Graduation, means the end of life in university, the end of these glorious, romantic years. Your lovely smile which is my original incentive to work hard and this unrequited love will be both sealed as a memory in the deep of my heart and my mind. Graduation, also means a start of new life, a footprint on the way to bright prospect. I truly hope you will be happy everyday abroad and everything goes well. Meanwhile, I will try to get out from puerility and become more sophisticated. To pursue my own love and happiness here in reality will be my ideal I never desert.

 Farewell, my princess!

 If someday, somewhere, we have a chance to gather, even as gray-haired man and woman, at that time, I hope we can be good friends to share this memory proudly to relight the youthful and joyful emotions. If this chance never comes, I wish I were the stars in the sky and twinkling in your window, to bless you far away, as friends, to accompany you every night, sharing the sweet dreams or going through the nightmares together.

  

 

Here comes the problem: Assume the sky is a flat plane. All the stars lie on it with a location (x, y). for each star, there is a grade ranging from 1 to 100, representing its brightness, where 100 is the brightest and 1 is the weakest. The window is a rectangle whose edges are parallel to the x-axis or y-axis. Your task is to tell where I should put the window in order to maximize the sum of the brightness of the stars within the window. Note, the stars which are right on the edge of the window does not count. The window can be translated but rotation is not allowed.

Input

There are several test cases in the input file. The first line of each case contains 3 integers: n, W, H, indicating the number of stars, the horizontal length and the vertical height of the rectangle-shaped window. Then n lines follow, with 3 integers each: x, y, c, telling the location (x, y) and the brightness of each star. No two stars are on the same point.

 There are at least 1 and at most 10000 stars in the sky. 1<=W,H<=1000000, 0<=x,y<2^31.

Output

For each test case, output the maximum brightness in a single line.

Sample Input

3 5 41 2 32 3 26 3 13 5 41 2 32 3 25 3 1

Sample Output

56

// Problem#: 1092
// Submission#: 3416882
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <string.h>
#include <math.h>
#include <list>
using namespace std;

int N, W, H;
const int MAXN = 20010;

struct point {
    long long x, y, s;
    point() {}
    point(long long a, long long b, long long c) {
        x = a, y = b, s = c;
    }
};

point p[MAXN];
long long Y[MAXN], sum[MAXN << 2], Max[MAXN << 2];

bool cmp(const point & p1, const point & p2) {
    if (p1.x == p2.x) return p1.s < p2.s;
    return p1.x < p2.x;
}

int Find(int l, int r, long long target) {
    while (l < r) {
        int mid = (l + r) >> 1;
        if (Y[mid] < target) l = mid + 1;
        else r = mid;
    }
    return l;
}

void up(int idx) {
    int ls = idx << 1, rs = idx << 1 | 1;
    sum[idx] = sum[ls] + sum[rs];
    Max[idx] = Max[ls];
    if (Max[idx] < sum[ls] + Max[rs]) Max[idx] = sum[ls] + Max[rs];
}

void update(int l, int r, int idx, int pos, long long val) {
    if (l == r) {
        sum[idx] += val;
        Max[idx] += val;
        return;
    }
    int mid = (l + r) >> 1;
    int ls = idx << 1, rs = idx << 1 | 1;
    if (pos <= mid) update(l, mid, ls, pos, val);
    else update(mid + 1, r, rs, pos, val);
    up(idx);
}

int main() {

    std::ios::sync_with_stdio(false);

    while (1) {
        cin >> N >> W >> H;
        if (cin.eof()) break;
        long long x, y, v;
        for (int i = 0; i < N; i++) {
            cin >> x >> y >> v;
            p[i << 1] = point(x, y, v);
            p[i << 1 | 1] = point(x + W, y, -v);
            Y[i << 1] = y;
            Y[i << 1 | 1] = y + H;
        }
        int m = N << 1;
        sort(Y, Y + m);
        sort(p, p + m, cmp);
        int n = 1;
        for (int i = 1; i < m; i++) {
            if (Y[i] != Y[i - 1]) Y[n++] = Y[i];
        }
        n--;
        memset(sum, 0, sizeof(sum));
        memset(Max, 0, sizeof(Max));
        long long ans = 0;
        for (int i = 0; i < m; i++) {
            int s = Find(0, n, p[i].y);
            int e = Find(0, n, p[i].y + H);
            if (ans < Max[1]) ans = Max[1];
            update(0, MAXN, 1, s, p[i].s);
            update(0, MAXN, 1, e, -p[i].s);
        }
        cout << ans << endl;
    }

    return 0;
}                                 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值