8.17 第九场 Unfair contest

8.17 第九场 Unfair contest

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2049 Accepted Submission(s): 254

Problem Description

I’m going to give my scores fairly. It’s just that some contestant deserves a fairer score…

gispzjz and zyb are participating in a contest, with n referees awarding scores(according to their performance, usually) to them. For each contestant, each referee should name an integer in the interval [1,h] as the score, and the final score of the contestant is the sum over all scores he gets after eliminating s highest scores and t lowest scores.

As one of the referees, you had a bet on gispzjz, so you want him to win this contest, but you also don’t want this to look too obvious. Suppose you know the other n−1 referees have awarded scores a1,…,an−1 to gispzjz and b1,…,bn−1 to zyb. You need to give out your scores an and bn so that the final score of gispzjz is strictly higher than zyb. If that’s achievable, you also need to minimize an−bn, conditioned on the final score of gispzjz is strictly higher than zyb.

Input

The first line contains a number T(1≤T≤12000), denoting the number of test cases.

The first line of each test case contains four integers n,s,t,h(1≤n≤105,0≤s,t≤n−1,1≤h≤109), denoting the number of referees, the number of highest and lowest scores that need to be eliminated, and the scoring range for referees, respectively. It is guaranteed that s+t≤n−1.

Then one line containing n−1 integers a1,…,an−1(1≤ai≤h) follow, denoting the scores already awarded to gispzjz.

Then another line containing n−1 integers b1,…,bn−1(1≤bi≤h) follow, denoting the scores already awarded to zyb.

It is guaranteed that ∑n≤106 over all test cases.

Output

For each test case, if it’s possible to make gispzjz’s score strictly higher than zyb, then output the minimized an−bn in one line, otherwise output “IMPOSSIBLE”(without quotes) in one line.

Sample Input

3
3 1 1 4
1 3
2 4
4 1 1 9
4 4 5
4 5 5
4 1 1 9
4 5 5
4 4 5

Sample Output

1
IMPOSSIBLE
-4

大概题意:

最后一个评委对两个选手打分,怎么打分能让第一个选手赢

思路:

排序后模拟打分,分情况讨论即可

代码:

//
// Created by Black on 2021/8/17.
//

#include <iostream>
#include <set>
#include <algorithm>
#include <cstdio>

using namespace std;
const int N = 100010;
int n, m, T, s, t, h;
long long a[N];
long long b[N];

int main() {
//    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    scanf("%d", &T);
    while (T--) {
        scanf("%d%d%d%d", &n, &s, &t, &h);
        for (int i = 1; i < n; ++i) {
            scanf("%d", &a[i]);
        }
        for (int i = 1; i < n; ++i) {
            scanf("%d", &b[i]);
        }
        a[0] = b[0] = 1;
        a[n] = b[n] = h;
        sort(a + 1, a + n);
        sort(b + 1, b + n);
        long long res1 = 0, res2 = 0;
        for (int i = t + 1; i < n - s; ++i) {
            res1 += a[i];
            res2 += b[i];
        }
        if (b[2] == 4 && b[3] == 5) {
            int k;
        }
        long long amin = res1 + a[t];
        long long amax = res1 + a[n - s];
        long long bmin = res2 + b[t];
        long long bmax = res2 + b[n - s];
        if (amax <= bmin)puts("IMPOSSIBLE");
        else if (amin > bmax)printf("%d\n", 1 - h);
        else {
            long long ans = 0;
            if (amin > bmin)ans = max(ans, a[t] - 1);
            if (amax > bmax)ans = max(ans, h - b[n - s]);
            printf("%d\n", res2 - res1 + 1 - ans);
        }

    }
    return 0;
}
posted @   嘿,抬头!  阅读(17)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
点击右上角即可分享
微信分享提示