Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 【树状数组维护区间最大值】...

题目传送门:http://codeforces.com/contest/799/problem/C

C. Fountains

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
 

Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are allowed.

Help Arkady to find two fountains with maximum total beauty so that he can buy both at the same time.

Input

The first line contains three integers nc and d (2 ≤ n ≤ 100 000, 0 ≤ c, d ≤ 100 000) — the number of fountains, the number of coins and diamonds Arkady has.

The next n lines describe fountains. Each of these lines contain two integers bi and pi (1 ≤ bi, pi ≤ 100 000) — the beauty and the cost of the i-th fountain, and then a letter "C" or "D", describing in which type of money is the cost of fountain i: in coins or in diamonds, respectively.

Output

Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.

Examples
input
3 7 6
10 8 C
4 3 C
5 6 D
output
9
input
2 4 5
2 5 C
2 1 D
output
0
input
3 10 10
5 5 C
5 5 C
10 11 D
output
10

Note

In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9.

In the second example there are two fountains, but Arkady can't build both of them, because he needs 5 coins for the first fountain, and Arkady has only 4 coins.

 

题目大意:

有 N 个水池,每个水池有 观赏值 和 花费(金币或者钻石);Arkady有 C 个金币 D 个钻石,他想建两个水池,使得观赏值最高。

解题思路:

树状数组维护金币和钻石花费范围内所能得到的最大值,每次输入都比较三种可能性一个金币的一个钻石的,两个金币的,两个钻石的。

 

AC code:

 1 #include <bits/stdc++.h>
 2 #define INF 0x3f3f3f3f
 3 #define ll long long int
 4 using namespace std;
 5 
 6 const int MAXN = 1e5+10;
 7 
 8 int t_1[MAXN], t_2[MAXN];
 9 int N, num_c, num_d;
10 
11 int lowbit(int x)
12 {
13     return x&(-x);
14 }
15 void add(int no, int st, int value)
16 {
17     for(int i = st; i <= MAXN; i+=lowbit(i))
18     {
19         if(no) t_1[i] = max(t_1[i], value);
20         else t_2[i] = max(t_2[i], value);
21     }
22 }
23 
24 int query(int no, int st)
25 {
26     int res = 0;
27     for(int i = st; i > 0; i-=lowbit(i))
28     {
29         if(no) res = max(res, t_1[i]);
30         else res = max(res, t_2[i]);
31     }
32     return res;
33 }
34 int main()
35 {
36     char str[3];
37     int ans_max = 0, a, b, ans = 0;
38     scanf("%d%d%d", &N, &num_c, &num_d);
39     for(int i = 1; i <= N; i++)
40     {
41         scanf("%d%d", &a, &b);
42         scanf("%s", str);
43         if(str[0] == 'C'){
44             ans_max = query(0, num_d);
45             if(b > num_c) continue;
46             ans_max = max(ans_max, query(1, num_c-b));
47             add(1, b, a);
48         }
49         else{
50             ans_max = query(1, num_c);
51             if(b > num_d) continue;
52             ans_max = max(ans_max, query(0, num_d-b));
53             add(0, b, a);
54         }
55         if(ans_max) ans = max(ans, ans_max+a);
56     }
57     printf("%d\n", ans);
58     return 0;
59 }
View Code

 

转载于:https://www.cnblogs.com/ymzjj/p/9538480.html

本项目是一个基于SSM(Spring+SpringMVC+MyBatis)框架和Vue.js前端技术的家教平台系统。该系统旨在为家教和学生提供一个便捷、高效的在线交流和预约平台,涵盖了从用户注册登录、个人信息管理、课程发布与搜索、预约与取消预约、评价反馈等一系列功能。 在后台管理方面,系统提供了管理员对用户信息、课程信息、预约记录等进行管理的功能,确保平台的正常运行和数据的准确性。通过Spring框架的依赖注入和AOP特性,实现了业务逻辑的清晰分离和高效处理;SpringMVC则负责处理前端请求和响应,提供友好的用户界面;MyBatis作为ORM框架,简化了数据库操作,提高了数据访问的效率和安全性。 前端部分采用Vue.js框架,结合Vue Router进行页面路由管理,Axios进行HTTP请求,实现了前后端分离的开发模式。Vue.js的组件化开发和响应式数据绑定特性,使得前端页面更加动态和交互性强,提升了用户体验。 数据库设计采用了MySQL,存储了用户信息、课程信息、预约记录等核心数据。通过合理的数据库表结构和索引设计,保证了系统的高效运行和数据的一致性。 该项目不仅适合计算机相关专业的毕设学生参考和学习,也适合Java学习者进行项目实战练习。通过对该项目的深入理解和二次开发,可以实现更多个性化功能,进一步提升技术水平和实践能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值