codeforces738C

点击打开链接

题意:

       

思路: 

    一个车能不能选只和它的油箱容量有关,所以按照油箱排序,找到一个合适的最小容量即可,再求一下最优即可。

#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;

const int maxn = 2e5 + 10;

int n, k, s, t, mint;

struct node
{
    int c, tank;
    friend bool operator < (node a, node b)
    {
        return a.tank < b.tank;
    }

}a[maxn];

int g[maxn];

bool check(int x)
{
    int nowtank = a[x].tank;
    double tx = 1.0 * mint;
    for(int i = 1; i <= k; i++)
    {
        nowtank = a[x].tank;
        int len = g[i] - g[i-1];
        if(len > nowtank)
            return false;
        else if(nowtank > 2*len)
            nowtank = 2*len;
        tx = tx - 1.0*(nowtank - len);
    }
    nowtank = a[x].tank;
    int len = s - g[k];
    if(len > nowtank)
        return false;
    else
    {
        if(nowtank > 2*len)
            nowtank = 2*len;
        tx = tx - 1.0*(nowtank - len);
    }
    if(tx>0)
        return false;
    else
        return true;
}

int main()
{
    scanf("%d%d%d%d", &n, &k, &s, &t);
    if(s > t)
    {
        cout<<-1<<endl;
        return 0;
    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d%d", &a[i].c, &a[i].tank);
    }
    for(int i = 1; i <= k; i++)
    {
        scanf("%d", &g[i]);
    }
    sort(a+1, a+1+n);
    sort(g+1, g+k+1);
    mint = t-2*(t-s);
    int l = 0, r = n+1, mid;
    bool flag =false;
    while(l < r)
    {
        mid = (l+r)/2;
        if(check(mid))
        {
              r = mid;
              flag = true;
        }
        else
            l = mid+1;
    }
    int minc = 2e9;
    if(!flag)
    {
        cout<<-1<<endl;
        return 0;
    }
    for(int i = r; i <= n; i++)
        minc = min (minc, a[i].c);
    printf("%d\n", minc);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程熊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值