题解 | 小红拿石子1.0

小红拿石子1.0

https://www.nowcoder.com/practice/537ba6fa73d84d26b03196caed197772

#include <iostream>
#include<queue>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    priority_queue<int,vector<int>>heap;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        heap.push(a);
    }
    int cnt=0;
    long long sum=0;
    while(!heap.empty()){
        int t=heap.top();
        heap.pop();
        if(t<=cnt)break;
        sum+=t-cnt;
        cnt++;
    }
    cout<<sum<<endl;
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务