社区讨论

60 pts hack全过求条

P2672[NOIP 2015 普及组] 推销员参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mii8v8xd
此快照首次捕获于
2025/11/28 10:29
3 个月前
此快照最后确认于
2025/11/29 13:55
3 个月前
查看原帖
WA 后4个点 错的点都是输出小了
CPP
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
#define int long long
int n;
// int a[100005],b[100005];
int pos=0,hzmx[100005][2];
struct zuoti {
    int val;
    int xb;
};
struct zuoti2{
    int jl;
    int hf;
}zt[10005];
// bool operator < (zuoti a,zuoti b){
//     return a.val<b.val;
// }
priority_queue<int>pq;
bool cmp(zuoti2 a,zuoti2 b){
    if(a.jl==b.jl)return a.hf>b.hf;
    return a.jl<b.jl;
}
int ans=0;
signed main(){
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> zt[i].jl;
    }
    for(int i=1;i<=n;i++){
        cin >> zt[i].hf;
    }
    sort(zt+1,zt+1+n,cmp);
    for(int i=n;i>=1;i--){
        if(zt[i].jl*2+zt[i].hf>hzmx[i+1][0]){
            hzmx[i][0]=zt[i].jl*2+zt[i].hf;
            hzmx[i][1]=i;
        }
        else {
            hzmx[i][0]=hzmx[i+1][0];
            hzmx[i][1]=hzmx[i+1][1];
        }
    }
    for(int i=1;i<=n;i++){
        // zuoti tmp;
        // tmp.val=0;tmp.xb=0;
        int tmp=0;
        if(!pq.empty()){
            tmp=pq.top();
            // cout << "TANG" << pq.top() << endl;
        }
        if(tmp>hzmx[pos+1][0]-2*zt[pos].jl){
            // cout << "JIN";
            ans+=tmp;
            pq.pop();
        }
        else {
            ans+=hzmx[pos+1][0];
            // cout << ans << ":TEST\n";
            ans-=2*zt[pos].jl;
            for(int j=pos+1;j<hzmx[pos+1][1];j++){
                pq.push(zt[j].hf);
            }
            pos=hzmx[pos+1][1];
        }
        cout << ans << endl;
    }
    return 0;
    
}

回复

0 条回复,欢迎继续交流。

正在加载回复...