ICPC Latin American Regional – 2017

Problem F – Fundraising

Author: Paulo Cezar Pereira Costa, Brasil

A prestigious politician aiming for presidency next year is planning a fundraising dinner for her cam-paign. She has a list of some wealthy people in the country and wants to invite them in a way that the amount of money raised is as great as possible.

Sometimes wealthy people have futile behavior and don’t like the idea that someone richer or prettier than them exists. Every time someone like this meets another person who is strictly prettier, but not strictly richer, then an argument ensues. Likewise, if they meet another person who is strictly richer,but not strictly prettier, an argument occurs as well. These two situations are the only possible causes of an argument involving two persons. Thus, two persons do not have an argument if one of them is strictly prettier and strictly richer than the other. Also, two persons do not have an argument if they are equally rich and equally pretty.Since the presidential candidate wants to raise as much money as possible, an argument should be avoided at all costs, as it could ruin the campaign. Given the characteristics of some wealthy people in the country, you must find a guest list that maximizes the donations while ensuring that no argument will happen during the dinner.

Input

The first line contains an integer N(1≤N≤10^5) representing the number of possible guests with known characteristics. Each of the next N lines describes a possible guest with three integers B,F and D(1≤B, F, D≤10^9), indicating respectively the person’s beauty, his/her fortune, and how much this person will donate if invited.

Output

Output a single line with an integer indicating the maximum sum of donations if guests are invited so that no argument will happen during the dinner.

Sample input 1

4

1 2 50

2 1 50

2 2 30

1 1 30

Sample output 1

60

Sample input 2

3

3 3 3

5 5 3

2 2 3

Sample output 2

9

Sample input 3

3

2 8 13

1 4 12

2 1 16

Sample output 3

25

题意:

每个人有两个属性值,以及一个权值,如果两个人的属性值都相同或者某个人的两个属性值分别大于另一个人,那么这两个人可以同时选出来,求选出一些人使得权值和最大。

题解:

先把两个属性值都相同的人合并,然后按第一个属性值从小到大排序,这样就能变成一维问题。需要注意的是当第一个属性值相同时第二个属性值要按从大到小排序(巧妙)。然后就是裸的带权最长上升子序列,肯定是用树状数组没跑了。

代码:

#include <bits/stdc++.h>using namespace std;const int MAXN = 100005;long long tree[MAXN];
int len;int bin[MAXN];//用于二分 int lowbit(int t)
{return t&(-t);
}void Updata(int index,long long value)
{for(int i=index ; i<=len ; i+=lowbit(i)){tree[i] = max(tree[i],value);}
}long long Query(int index)//区间查询最大值
{long long sum = 0;for(int i=index ; i>0 ; i-=lowbit(i)){sum = max(sum,tree[i]);}return sum;
}struct cmp_key//map自定义排序
{bool operator()(const pair<int,int> &k1,const pair<int,int> &k2) const{if(k1.first != k2.first){return k1.first < k2.first;}else return k1.second > k2.second;return false;}
};int Bin(int x){int l = 1,r = len;while(l <= r){int m = l + (r-l)/2;if(bin[m] == x)return m;else if(bin[m] > x)r = m-1;else l = m+1;}return -1;
}map<pair<int,int>,long long,cmp_key> MMP;inline void init(){MMP.clear();memset(tree,0,sizeof tree);
}int main(){int N;while(scanf("%d",&N) == 1){init();int a,b;long long v;for(int i=1 ; i<=N ; ++i){scanf("%d %d %lld",&a,&b,&v);if(MMP.find(make_pair(a,b)) == MMP.end())MMP[make_pair(a,b)] = v;else MMP[make_pair(a,b)] += v;bin[i] = b;}map<pair<int,int>,long long,cmp_key>::iterator it;
//      for(it=MMP.begin() ; it!=MMP.end() ; ++it){
//          printf("%d %d %lld\n",(*it).first.first,(*it).first.second,(*it).second);
//      }sort(bin+1,bin+1+N);len = unique(bin+1,bin+1+N)-(bin+1);//去重 for(it=MMP.begin() ; it!=MMP.end() ; ++it){int ind = Bin((*it).first.second);long long t = Query(ind-1);Updata(ind,t+(*it).second);}printf("%lld\n",Query(len));}return 0;
}

Gym - 101889F Fundraising(树状数组求带权最长上升子序列)相关推荐

  1. 牛客练习赛33 D tokitsukaze and Inverse Number (树状数组求逆序对,结论)

    链接:https://ac.nowcoder.com/acm/contest/308/D 来源:牛客网 tokitsukaze and Inverse Number 时间限制:C/C++ 1秒,其他语 ...

  2. nyoj 1261 音痴又音痴的LT(离散化+树状数组求K小数)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=1261 解题思路:比较水的题,用离散化+树状数组求K小数即可,先用一次离线处理. #inc ...

  3. hdu1754(树状数组求最值问题)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. poj 2299 Ultra-QuickSort(树状数组求逆序数+离散化)

    题目链接:http://poj.org/problem?id=2299 Description In this problem, you have to analyze a particular so ...

  5. 离散化+树状数组求逆序数

    题目:http://poj.org/problem?id=2299 离散化是一种常用的技巧,有时数据范围太大,可以用来放缩到我们能处理的范围 因为其中需排序的数的范围0--- 999999999:显然 ...

  6. loj #535. 「LibreOJ Round #6」花火 树状数组求逆序对+主席树二维数点+整体二分...

    $ \color{#0066ff}{ 题目描述 }$ 「Hanabi, hanabi--」 一听说祭典上没有烟火,Karen 一脸沮丧. 「有的哦-- 虽然比不上大型烟花就是了.」 还好 Shinob ...

  7. Tido 习题-二叉树-树状数组求逆序对

    这里给大家提供一个全新的求逆序对的方法 是通过树状数组来实现的 题目描述   样例输入 Copy 5 2 3 1 5 4 样例输出 Copy 3 提示       #include<iostre ...

  8. 树状数组求逆序对_初识树状数组

    树状数组是用来解决数列多次单点修改和前缀和查询的利器. 首先我们来看问题的原型: 已知一个长度为n(n<=10 0000)的数列,初始值都是零,现在我们要对数列施加两种类型的操作共q(q< ...

  9. 树状数组求区间和模板 区间可修改 参考题目:牛客小白月赛 I 区间

    从前有个东西叫树状数组,它可以轻易实现一些简单的序列操作,比如单点修改,区间求和;区间修改,单点求值等. 但是我们经常需要更高级的操作,比如区间修改区间查询.这时候树状数组就不起作用了,只能选择写一个 ...

最新文章

  1. 忘了root口令解决方法
  2. stutBar的使用
  3. linux下查看mysql数据库的字段类型_系统运维|[小白技巧]如何在Linux上检查MySQL数据表的存储引擎类型...
  4. python报“IndentationError: unexpected indent“的解决方法
  5. 太原理工大学ICPC队介绍(2019版)
  6. 部署ganglia3.7
  7. Tips for ASP.NET Application Performance Enhancement
  8. 278.第一个错误版本(力扣leetcode) 博主可答疑该问题
  9. 轻松斩断信息安全黑手!就这?
  10. 常用命令和常用工作地址管理工具
  11. yaahp使用教程_结合层次分析法和模糊综合评价法的评价方法-利用yaahp
  12. iOS中常用的颜色色值
  13. 关于ICP和EDI许可证,你了解多少?
  14. php微信零钱明细,微信钱包的收支记录明细在哪里查看,看完就明白了
  15. 永远的友谊_友谊的传递属性-温馨介绍的重要性
  16. office卸载重新安装,并安装mathtype7数学编辑公式
  17. python 发邮件 带附件
  18. 【语义分割】语义分割经典模块
  19. 明确不站队BAT,帆软——这家只有几百人的BI公司靠什么赢得生存?
  20. 三点确定一个圆(输出圆心、弧长、圆心角、方向)

热门文章

  1. 做视觉UI设计时,都需要注意哪些常见的基础错误
  2. 如何为 Ubuntu 扩容(添加新的硬盘空间)?
  3. 645仪表以JSON格式上发方法
  4. 杰理之ANC控制【篇】
  5. Maven安装配置和私服搭建
  6. 射频识别(RFID)原理总结
  7. java 地图四色着色算法_四色定理的简单证明:从四色猜想到四域公理
  8. 2. 事件捕获 及 如何阻止冒泡
  9. JS中修改元素内容,属性,样式的方法【详解】
  10. JZOJ ???? 细胞