• CodeForces 222D Olympiad


    D. Olympiad
    time limit per test:1 second
    memory limit per test:256 megabytes
    input:standard input
    output:standard output

    A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least x points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.

    Help Vasya's teacher, find two numbers — the best and the worst place Vasya could have won. Note that the total results' table sorts the participants by the sum of points for both tours (the first place has the participant who has got the most points). If two or more participants have got the same number of points, it's up to the jury to assign places to them according to their choice. It is guaranteed that each participant of the Olympiad participated in both tours of the Olympiad.

    Input

    The first line contains two space-separated integers n, x (1 ≤ n ≤ 105; 0 ≤ x ≤ 2·105) — the number of Olympiad participants and the minimum number of points Vasya earned.

    The second line contains n space-separated integers: a1, a2, ..., an (0 ≤ ai ≤ 105) — the participants' points in the first tour.

    The third line contains n space-separated integers: b1, b2, ..., bn (0 ≤ bi ≤ 105) — the participants' points in the second tour.

    The participants' points are given in the arbitrary order. It is guaranteed that Vasya was present in the Olympiad — there are two integers i, j (1 ≤ i, j ≤ n) such, that ai + bj ≥ x.

    Output

    Print two space-separated integers — the best and the worst place Vasya could have got on the Olympiad.

    Examples
    Input
    5 2
    1 1 1 1 1
    1 1 1 1 1
    Output
    1 5
    Input
    6 7
    4 3 5 6 4 4
    8 6 0 4 3 4
    Output
    1 5
    Note

    In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.

    In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the total results' table looks like that — {4:8, 6:4, 3:6, 4:4, 4:3, 5:0}.

    In this table all participants are sorted by decreasing points and we can see how much a participant earned in the first and in the second tour.

    In the worst case scenario Vasya can get the fifth place if the table looks like that — {4:8, 4:6, 6:4, 5:4, 4:3, 3:0}, and he earned 4 and 3 points in the first and second tours, correspondingly.

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <algorithm>
     4 using namespace std;
     5 const int maxn=100005;
     6 int a[maxn],b[maxn];
     7 int main()
     8 {
     9     int n,x,r,pos,ans;
    10     while(scanf("%d%d",&n,&x)==2){
    11         for(int i=0;i<n;i++) scanf("%d",&a[i]);
    12         for(int i=0;i<n;i++) scanf("%d",&b[i]);
    13         sort(a,a+n);
    14         sort(b,b+n);
    15         int i=n-1,j=0;
    16         for(;i>=0;i--){
    17             while(x>a[i]+b[j] && j<n) j++;
    18             if(j>=n) break;
    19             j++;
    20         }
    21         printf("1 %d
    ",n-i-1);
    22     }
    23 
    24 }
  • 相关阅读:
    RDLC报表开发技巧备忘
    C#3.0"扩展方法"简记
    将activity转化成view
    取消logcat输出
    低栏的项目切换
    android edittext 限制文本框输入的长度和提示信息
    android如何调用dotnet编写的webservice
    iphone 式退出
    几种tabhost的总结(1)
    切换浏览示意图
  • 原文地址:https://www.cnblogs.com/cumulonimbus/p/5826884.html
Copyright © 2020-2023  润新知