zoj 1731 Supermarket

zoj 1731 Supermarket,第1张

zoj 1731 Supermarket
#include <iostream>#include <cstdio>#include <queue>#include <cstring>using namespace std;struct Schedule{    int profit;    int dt;    bool operator<(const Schedule &rhs)const {        return profit<rhs.profit;    }};bool used[10001];priority_queue<Schedule> que;int main(){    int n;    while(scanf("%d",&n)!=EOF){        while(!que.empty())que.pop();        int max = 0;        for (int i=0;i<n;i++){ Schedule prod; scanf("%d %d",&prod.profit,&prod.dt); if (prod.dt>max) max = prod.dt; que.push(prod);        }        memset(used,false,sizeof(bool)*(max+1));        long long sum =0;        int current = 0;        while(!que.empty()){ Schedule prod = que.top(); que.pop(); while(prod.dt--){     if (!used[prod.dt]){         used[prod.dt] = true;         sum+=prod.profit;         break;     } }        }        printf("%dn",sum);    }    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4907281.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存