zoukankan      html  css  js  c++  java
  • CodeForces462B

    Appleman and Card Game

    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    Appleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card i you should calculate how much Toastman's cards have the letter equal to letter on ith, then sum up all these quantities, such a number of coins Appleman should give to Toastman.

    Given the description of Appleman's cards. What is the maximum number of coins Toastman can get?

    Input

    The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105). The next line contains n uppercase letters without spaces — the i-th letter describes the i-th card of the Appleman.

    Output

    Print a single integer – the answer to the problem.

    Sample Input

    Input
    15 10
    DZFDFZDFDDDDDDF
    Output
    82
    Input
    6 4
    YJSNPI
    Output
    4

     1 //2016.8.2
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cstring>
     5 
     6 using namespace std;
     7 
     8 int ch[30];
     9 
    10 bool cmp(int a, int b)
    11 {
    12     return a>b;
    13 }
    14 
    15 int min(int a, int b)
    16 {
    17     return a > b ? b : a;
    18 }
    19 
    20 int main()
    21 {
    22     int n, k;
    23     long long ans, x;
    24     char c;
    25     while(cin >> n >> k)
    26     {
    27         memset(ch, 0, sizeof(ch));
    28         getchar();
    29         ans = 0;
    30         for(int i = 0; i < n; i++)
    31         {
    32             c = getchar();
    33             ch[c-'A']++;
    34         }
    35         sort(ch, ch+26, cmp);
    36 
    37         for(int i = 0; k > 0;i++)
    38         {
    39             x = min(k, ch[i]);
    40             ans += x*x;
    41             k -= x;
    42         }
    43         cout << ans << endl;
    44     }
    45     return 0;
    46 }
  • 相关阅读:
    不能交易的物料不可做接收
    限制车间备料方式更改
    成本维护不允许超过设定比例
    车间不可操作非车间仓
    手工成本维护不可以将成本改为零
    手工成本维护超过1500元提醒
    成本查询
    同一供应商只能有一个有效的报价单
    新增报价单状态为有效状态
    同一供应商同一物料存在有效报价时不能再新增报价
  • 原文地址:https://www.cnblogs.com/Penn000/p/5758137.html
Copyright © 2011-2022 走看看