促销活动

注意:因为账单金额有可能重复,所以需要使用multiset,另外结果会爆int

#include <stdio.h>
#include <iostream>
#include <stack>
#include <string>
#include <set>
#include <memory.h>
using namespace std;
multiset<int> record;
int days , Hash[1000005];
int main()
{
    scanf("%d", &days);
    long long ans = 0;
    memset(Hash, 0, sizeof(Hash));
    while( days-- )
    {
        int num;
        scanf("%d", &num);
        while( num-- )
        {
            int cost;
            scanf("%d", &cost);
            Hash[cost]++;
            record.insert(cost);
        }
        multiset<int>::iterator iter = record.end();
        iter--;
        int MaxCost = (*iter);
        Hash[MaxCost]--;
        record.erase(iter);
        iter = record.begin();
        int MinCost = (*iter);
        record.erase(iter);
        ans += (MaxCost - MinCost);
    }
    printf("%lld\n", ans);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/xutian_curry/article/details/80301898
今日推荐