zoukankan      html  css  js  c++  java
  • (树状数组)Codeforces Round #413 C-Fountains

    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.

    Example

    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.

     1 #include <iostream>
     2 #include <string>
     3 #include <algorithm>
     4 #include <cstring>
     5 #include <cstdio>
     6 #include <cmath>
     7 #include <queue>
     8 #include <set>
     9 #include <map>
    10 #include <list>
    11 #include <stack>
    12 #define mp make_pair
    13 typedef long long ll;
    14 typedef unsigned long long ull;
    15 const int MAX=1e5;
    16 const int INF=1e9+5;
    17 const double M=4e18;
    18 using namespace std;
    19 const int MOD=1e9+7;
    20 typedef pair<int,int> pii;
    21 const double eps=0.000000001;
    22 int C[MAX+5],D[MAX+5];
    23 void add(int *tree,int k,int num)
    24 {
    25     while(k<=MAX)
    26     {
    27         tree[k]=max(tree[k],num);
    28         k+=k&(-k);
    29     }
    30 }
    31 int read(int *tree,int k)
    32 {
    33     int re=0;
    34     while(k)
    35     {
    36         re=max(re,tree[k]);
    37         k-=k&(-k);
    38     }
    39     return re;
    40 }
    41 int n,c,d,b,p;
    42 int an,tem;
    43 char opt[10];
    44 int main()
    45 {
    46     scanf("%d%d%d",&n,&c,&d);
    47     while(n--)
    48     {
    49         scanf("%d%d%s",&b,&p,opt);
    50         tem=0;
    51         if(opt[0]=='C')
    52         {
    53             if(p>c)
    54                 continue;
    55             tem=read(D,d);
    56             tem=max(tem,read(C,c-p));
    57             add(C,p,b);
    58         }
    59         else
    60         {
    61             if(p>d)
    62                 continue;
    63             tem=read(C,c);
    64             tem=max(tem,read(D,d-p));
    65             add(D,p,b);
    66         }
    67         if(tem)
    68             an=max(an,tem+b);
    69     }
    70     printf("%d
    ",an);
    71     return 0;
    72 }
    View Code

    第一次写BIT,感觉比起线段树代码量的确少的多,但现在比较复杂的操作还不会用bit写……

  • 相关阅读:
    CF1264E Beautiful League 解题报告
    CF1411G No Game No Life 解题报告
    Data structure on Bitcoin
    bitcoin Cryptography
    弹性布局Flex的基本语法
    Linq操作list
    dt某字段赋值
    List 添加数据
    dt 转 json 转实体
    队列
  • 原文地址:https://www.cnblogs.com/quintessence/p/6852954.html
Copyright © 2011-2022 走看看