Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem 贪心,二分

题目链接:这里
题意:c[i]=b[i]-a[i],现在给你a[i]和c[i]的相对大小,问你可不可能出现b[i]满足条件,如果有的话,输出。
解法:贪心,最小的显然要最小,次小的在比最小大的基础上最小就好了。对于每一个数都二分一下就完了。
二分的时候把l打成了1,死活WA19。。。

//CF 761D

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
long long l, r, a[maxn], b[maxn], c[maxn];
priority_queue <pair<int, int> > S;
int n;
int main(){
    cin >> n >> l >> r;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        S.push(make_pair(x, i));
    }
    long long last = -1e16;
    while(!S.empty()){
        long long now = S.top().second;
        S.pop();
        long long L = l, R = r, ans = r+1;
        while(L <= R){
            long long mid = (L + R) / 2;
            if(a[now] - mid > last){
                L = mid + 1, ans = mid;
            }
            else{
                R = mid - 1;
            }
        }
        if(ans == r+1){
            puts("-1");
            return 0;
        }
        b[now] = ans;
        last = a[now] - ans;
    }
    for(int i = 0; i < n; i++) cout << b[i] << " "; cout << endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值