zoukankan      html  css  js  c++  java
  • Codeforces Round #322 (Div. 2) C. Developing Skills 优先队列

    C. Developing Skills

    Time Limit: 1 Sec  

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/581/problem/C

    Description

    Petya loves computer games. Finally a game that he's been waiting for so long came out!

    The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is calculated as the sum of the values ​​of  for all i from 1 to n. The expression ⌊ x⌋ denotes the result of rounding the number x down to the nearest integer.

    At the beginning of the game Petya got k improvement units as a bonus that he can use to increase the skills of his character and his total rating. One improvement unit can increase any skill of Petya's character by exactly one. For example, if a4 = 46, after using one imporvement unit to this skill, it becomes equal to 47. A hero's skill cannot rise higher more than 100. Thus, it is permissible that some of the units will remain unused.

    Your task is to determine the optimal way of using the improvement units so as to maximize the overall rating of the character. It is not necessary to use all the improvement units.

    Input

    The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal.

    The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-th skill of the character.

    Output

    The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units.

    Sample Input

    2 4
    7 9

    Sample Output

    2

    HINT

    题意

    有一个人有n个技能,有k个技能点

    每个技能最高10级,每点十个技能点算一级

    然后问你最后级数之和最高为多少

    题解:

    优先队列贪心就好了

    优先加离10进的数

    代码:

    //qscqesze
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <bitset>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 1205000
    #define mod 1000000007
    #define eps 1e-9
    #define e exp(1.0)
    #define PI acos(-1)
    #define lowbit(x) (x)&(-x)
    const double EP  = 1E-10 ;
    int Num;
    //const int inf=0x7fffffff;
    const ll inf=999999999;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //*************************************************************************************
    
    struct node
    {
        int x;
        bool operator<(const node& other)  const
        {
            if((x%10)==(other.x%10))return x>other.x;
            return (x%10)<(other.x%10);
        }
    };
    
    priority_queue<node> Q;
    int main()
    {
        int n=read(),k=read();
        for(int i=0;i<n;i++)
        {
            int x=read();
            Q.push(node{x});
        }
        while(k)
        {
            node now = Q.top();
            if(now.x==100)break;
            int p = min(10-now.x%10,k);
            now.x+=p;
            k-=p;
            Q.pop();
            Q.push(now);
        }
        int ans = 0;
        for(int i=0;i<n;i++)
        {
            node t = Q.top();
            ans += t.x/10;
            Q.pop();
        }
        cout<<ans<<endl;
    }
  • 相关阅读:
    OpenCV学习(10) 图像的腐蚀与膨胀(1)
    OpenCV学习(6) 文件和Mat之间的数据交换
    OpenCV学习(5) Mat的基本操作(2)
    OpenCV学习(4) Mat的基本操作(1)
    OpenCV学习(3) OpenCV框架
    OpenCV学习(2) OpenCV的配置
    OpenCV学习(1) OpenCV的安装
    Android触控屏幕Gesture(GestureDetector和SimpleOnGestureListener的使用教程) 分类:Androidandroid实例
    转载 C++实现的委托机制
    C++如何禁止掉对象的复制操作
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4845097.html
Copyright © 2011-2022 走看看