Unfair contest 模拟-分类讨论

题意 :

  • 两人比赛,n个裁判,给分范围 [ 1 , h ] [1, h] [1,h],去掉s个最高分和t个最低分,给出n - 1个裁判的给分,第n个裁判想让第1个人赢,并且最小化给1的分数 a [ n ] a[n] a[n] - 给2的分数 b [ n ] b[n] b[n]

思路 :

  • 显然得出impossible的情况和直接输出“1 - h“的情况后,第一个人的最后得分为了比第二个人高,需要ax比bx高sumb - suma + 1分(相对,不论正负),事实上由于弹性移动,an可能可以更左,bn 可能可以更右,因此分类讨论。
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <ctime>
#define endl '\n'
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define lowbit(x) (x&-x)
using namespace std;
const double pi = acos(-1);
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;

const int N = 1e5 + 10;

ll a[N], b[N];

int main()
{
    IOS;
    
    int _; cin >> _;
    
    while (_ -- )
    {
        ll n, s, t, h;
        cin >> n >> s >> t >> h;
        for (int i = 1; i <= n - 1; i ++ ) cin >> a[i];
        for (int i = 1; i <= n - 1; i ++ ) cin >> b[i];
        
        sort(a + 1, a + n);
        sort(b + 1, b + n);
        
        // s = 0 / t = 0
        a[0] = b[0] = 1;
        a[n] = b[n] = h;
        
        ll suma = 0, sumb = 0;
        int l = t + 1, r = n - 1 - s;
        for (int i = l; i <= r; i ++ ) suma += a[i], sumb += b[i];
        
        ll amx = suma + a[r + 1], ami = suma + a[l - 1];
        ll bmx = sumb + b[r + 1], bmi = sumb + b[l - 1];
        
        if (ami > bmx) cout << 1 - h << endl;
        else if (amx <= bmi) cout << "IMPOSSIBLE" << endl;
        else
        {
            ll ans = 0;
            if (ami > bmi) ans = max(ans, a[l - 1] - 1);
            if (amx > bmx) ans = max(ans, h - b[r + 1]);
            cout << sumb - suma + 1 - ans << endl;		// 至少需要的差值减去可以更大的差值部分
        }
    }
    
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值