Problem H: tmk买礼物

传送门:http://gdutcode.sinaapp.com/problem.php?cid=1057&pid=7

Problem H: tmk买礼物_第1张图片

题解:

Problem H: tmk买礼物_第2张图片

实现代码;

#include 
#include 
#include 
#include 
using namespace std;

const int MAXN=1000010;
int a[MAXN];


int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        scanf("%d",&n);
        for(int i=0;i)
            scanf("%d",&a[i]);
        sort(a,a+n);
        long long ans=0;
        for(int i=0;i1;i++)
            ans+=a[i];
        cout<endl;
    }
}

 

转载于:https://www.cnblogs.com/IKnowYou0/p/6632740.html

你可能感兴趣的:(php,数据结构与算法)