//字符串价值,大顶堆,每次取次数最大值减一,然后调整k次,最后算平方和 int main() {     string s;     int n;     while (cin >> s >> n) {         vector<int> vec(26, 0);         priority_queue<int> pq;         long long res = 0;         for (auto ch : s) {             vec[ch - 'a']++;         }         for (int i = 0; i < 26; ++i) {             if (vec[i] > 0) pq.push(vec[i]);         }         while (n--) {             int num = pq.top(); pq.pop();             pq.push(--num);         }         while (!pq.empty()) {             int num = pq.top(); pq.pop();             res += num * num;         }         cout << res << endl;     }     return 0; }
点赞 4

相关推荐

不知道怎么取名字_:28届都开始出来找机会了,看来哪里都卷
实习简历求拷打
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务