Codeforces Round #427 (Div. 2) B

来源:互联网 发布:手机淘宝达人登录入口 编辑:程序博客网 时间:2024/05/16 09:38

题意:告诉你一个最长 长度为100000 的数字, 一个K,要求你改变(改变每一位数字的大小),使得 ∑每一位 的值可以>=k。

思路: 暴力。。 似乎我的太暴力了,直接优先队列维护。差点就超时了…

#include <bits/stdc++.h>using namespace std;typedef long long ll;const int maxn=1e6;char s[maxn];int cnt=0;priority_queue <int,vector <int>,greater<int> > a;int main(void){    int k;    cin >> k;    scanf("%s",s);    ll sum=0;    for(int i=0; i<strlen(s); i++)    {        sum+=s[i]-'0';        a.push(s[i]-'0');    }    if(sum>=k)    {        printf("0\n");        return 0;    }    else    {        while(1)        {            int x=a.top();            a.pop();            sum+=(9-x);            cnt++;            if(sum>=k)                break;        }    }    cout << cnt << endl;}

// 早上好繁琐~~