zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 43 E. Well played!(贪心)

    E. Well played!
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:

    Max owns n creatures, i-th of them can be described with two numbers — its health hpi and its damage dmgi. Max also has two types of spells in stock:

    1. Doubles health of the creature (hpi := hpi·2);
    2. Assigns value of health of the creature to its damage (dmgi := hpi).

    Spell of first type can be used no more than a times in total, of the second type — no more than b times in total. Spell can be used on a certain creature multiple times. Spells can be used in arbitrary order. It isn't necessary to use all the spells.

    Max is really busy preparing for his final exams, so he asks you to determine what is the maximal total damage of all creatures he can achieve if he uses spells in most optimal way.

    Input

    The first line contains three integers nab (1 ≤ n ≤ 2·105, 0 ≤ a ≤ 20, 0 ≤ b ≤ 2·105) — the number of creatures, spells of the first type and spells of the second type, respectively.

    The i-th of the next n lines contain two number hpi and dmgi (1 ≤ hpi, dmgi ≤ 109) — description of the i-th creature.

    Output

    Print single integer — maximum total damage creatures can deal.

    Examples
    input
    Copy
    2 1 1
    10 15
    6 1
    output
    Copy
    27
    input
    Copy
    3 0 3
    10 8
    7 11
    5 2
    output
    Copy
    26
    Note

    In the first example Max should use the spell of the first type on the second creature, then the spell of the second type on the same creature. Then total damage will be equal to 15 + 6·2 = 27.

    In the second example Max should use the spell of the second type on the first creature, then the spell of the second type on the third creature. Total damage will be equal to 10 + 11 + 5 = 26.

    题意:有n行数字,每行有h[i],d[i]. 

    你可以进行两种操作:

    a:h[i]=2*h[i]   

    b:  d[i]=h[i].     两种操作只能分别进行 :a, b次。

    问最后:sum(d[i])(i=1,2..n)的最大值。

    思路:遍历一遍,对每个i进行a次操作,讨论最优情况取最大值。

    代码:

     1 //#include"bits/stdc++.h"
     2 #include<sstream>
     3 #include<iomanip>
     4 #include"cstdio"
     5 #include"map"
     6 #include"set"
     7 #include"cmath"
     8 #include"queue"
     9 #include"vector"
    10 #include"string"
    11 #include"cstring"
    12 #include"time.h"
    13 #include"iostream"
    14 #include"stdlib.h"
    15 #include"algorithm"
    16 #define db double
    17 #define ll long long
    18 #define vec vectr<ll>
    19 #define mt  vectr<vec>
    20 #define ci(x) scanf("%d",&x)
    21 #define cd(x) scanf("%lf",&x)
    22 #define cl(x) scanf("%lld",&x)
    23 #define pi(x) printf("%d
    ",x)
    24 #define pd(x) printf("%f
    ",x)
    25 #define pl(x) printf("%lld
    ",x)
    26 //#define rep(i, x, y) for(int i=x;i<=y;i++)
    27 #define rep(i, n) for(int i=0;i<n;i++)
    28 const int N   = 1e6+ 5;
    29 const int mod = 1e9 + 7;
    30 const int MOD = mod - 1;
    31 const int inf = 0x3f3f3f3f;
    32 const db  PI  = acos(-1.0);
    33 const db  eps = 1e-10;
    34 using namespace std;
    35 int n;
    36 int A,B;
    37 int  a[N],b[N];
    38 priority_queue<int,vector<int>,greater<int>> q;
    39 int main() {
    40     ll ans = 0;
    41     cin >> n >> A >> B;
    42     for (int i = 0; i < n; i++) {
    43         cin >> a[i] >> b[i];
    44         if (a[i] > b[i]) q.push(a[i] - b[i]);
    45     }
    46     for (int i = 0; i < n; i++) ans += b[i];
    47     while (q.size() > B) q.pop();
    48     if (!B) return 0 * pl(ans);
    49     ll tans = ans;
    50     for (int i = 0; i < n; i++) {//讨论q长度与B的大小及i所处的位置
    51         ll x = a[i] * (1LL << A);
    52         if (q.size() && a[i] - b[i] >= q.top())
    53             tans = max(tans, ans - (a[i] - b[i]) + x - b[i]);
    54         else {
    55             if (q.size() < B)
    56                 tans = max(tans, ans + x - b[i]);
    57             else
    58                 tans = max(tans, ans - q.top() + x - b[i]);
    59         }
    60     }
    61     while (q.size()) {
    62         tans += q.top();
    63         q.pop();
    64     }
    65     pl(tans);
    66 }
  • 相关阅读:
    FastDFS介绍
    SwiftUI 中使用SDWebImageSwiftUI加载网络图片
    SwiftUI 中使用BBSwiftUIKit开源库实现上拉加载和下拉刷新
    SwiftUI 中使用ScrollView+LazyVStack代替List
    SwiftUI 动画
    SwiftUI 中实现省市区选择器
    SwiftUI 中Slider的使用
    SwiftUI 中Stepper的使用
    SwiftUI 中通过Toggle实现单选框和复选框效果
    SwiftUI 中加载bundle中的图片
  • 原文地址:https://www.cnblogs.com/mj-liylho/p/8976363.html
Copyright © 2011-2022 走看看