mnzn求助,为什么该代码过不了编译
  • 板块灌水区
  • 楼主xuzishuai
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/3/17 23:42
  • 上次更新2024/3/17 23:46:25
查看原帖
mnzn求助,为什么该代码过不了编译
486056
xuzishuai楼主2024/3/17 23:42

mnzn求助,下述代码无法过编译

/*
反悔贪心,每次都将油箱装满,如果遇到更便宜的油就换掉
为什么不能每次装最少的油等不够了在多买呢 ? 
原来是因为当不够时无法难以确定当前维护的最便宜的油是否还能买
*/
#include<bits/stdc++.h>
#define fq(i,d,u) for(int i(d); i<=u; ++i)
#define sf scanf
#define pf printf
#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 1e6+5;
int n,g,b,d;
struct cmp1{
    bool operator()(pii a,pii b){return a.second < b.second;}
};
/*nums price*/
multiset <pii,cmp1> fuel;
/*pos price*/
pii bd[N];
signed main(){

    cin>>n>>g>>b>>d;
    fq(i,1,n)
        cin>>bd[i].first>>bd[i].second;
    sort(bd + 1,bd + 1 + n);
    // fq(i,1,n) cout<<bd[i].first <<" "<<bd[i].second<<"%\n";
    bd[n+1] = {d,0};
    fuel.insert(b,0ll);
    int pos(0),ans(0),sum(b);
    fq(i,1,n + 1){
        int tmp(bd[i].first - pos);
        pos = bd[i].first;
        sum -= pos;
        if(sum < 0) {pf("-1\n"); exit(0);}
        while(tmp){
            auto it = fuel.begin();
            if(it->first <= tmp) tmp-=it->first,fuel.erase(it);
            else {
                tmp = 0;
                pii t = *it;
                t.first -= tmp;
                fuel.erase(it); fuel.insert(t);
            }
        }
        auto it = fuel.end();
        while(fuel.size() && it->second > bd->second){
            --it;
            ans -= (it->second)*(it->first);
            fuel.erase(it); it = fuel.end();
        }
        fuel.insert({g - sum,bd[i].second});
        ans += (g-sum)*(bd[i].second);
        sum = g;
    }
    cout << ans;

    return 0;
}
2024/3/17 23:42
加载中...