Jack_zhuiyi的博客

do what you want to do.

http://codeforces.com/problemset/problem/447/B DZY Loves Strings

插入最大权值放最后自然是最好的。

#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#define MAX 100005
#define mod 998244353ll
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
int a[26];
int main() {
    freopen("a.txt", "r", stdin);
    freopen("b.txt", "w", stdout);
    string s;
    int k;
    cin >> s >> k;
    int t = -INF;
    for (int i = 0; i < 26; ++i) {
        cin >> a[i];
        if (t < a[i]) {
            t = a[i];
        }
    }
    int len = s.length(), ans = 0;
    for (int i = 0; s[i]; ++i) {
        int t = s[i] - 'a';
        ans = ans + (i + 1) * a[t];
    }
    while (k--) {
        len++;
        ans = ans + len * t;
    }
    cout << ans << endl;
    return 0;
}
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Jack_zhuiyi/article/details/80686796
个人分类: codeforce-greedy
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭