CodeForces 222D Olympiad
来源:互联网 发布:workflow软件 编辑:程序博客网 时间:2024/06/05 05:17
http://codeforces.com/problemset/status
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.
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 integersi, j (1 ≤ i, j ≤ n) such, that ai + bj ≥ x.
Print two space-separated integers — the best and the worst place Vasya could have got on the Olympiad.
5 21 1 1 1 11 1 1 1 1
1 5
6 74 3 5 6 4 48 6 0 4 3 4
1 5
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.
题意是求所有能使ai + bj ≥ x.成立的组数中第一个,和最后一个各是第几。只要求出共有几个就哦了!!!!!!尼玛,
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int a[100100],b[100100];int n,x,ans=0;bool cmp(int a,int b){ return a>b;}int main(){ scanf("%d%d",&n,&x); for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<n;i++) scanf("%d",&b[i]); sort(a,a+n); sort(b,b+n,cmp); for(int i=0,j=0;i<n;i++)//a中从小到大,b中从大到小baoze { if(a[i]+b[j]>=x) { ans++;//计数 j++;//已经匹配j要加1,应为只能能用一次 } } printf("1 %d",ans); return 0;}
- CodeForces 222D Olympiad
- CodeForces 222D Olympiad
- CodeForces 222D Olympiad
- codeforces 222D Olympiad(贪心)
- Codeforces 222D Olympiad(贪心)
- codeforces 662D International Olympiad
- Codeforces 662D International Olympiad【贪心】
- CF 222D Olympiad 双指针
- Codeforces Team Olympiad(暴力)
- 【CODEFORCES】 A. Team Olympiad
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D. Jury Meeting(贪心)
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) D. Sorting the Coins 乱搞
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) A-D题解
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) D. Sorting the Coins
- Codeforces Round #441 (Div. 1, by Moscow Team Olympiad) D. High Cry
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) D. Sorting the Coins【规律】
- CodeForces 490A Team Olympiad
- CodeForces 550B Preparing Olympiad
- 字符和数字的转换函数
- 非线性规划 模型与基本概念
- 第四周 项目3 程序的多文件组织
- HDU3938 Portal
- PlayFramework+Maven+Eclipse
- CodeForces 222D Olympiad
- Jquery html 突出显示某张图片或文字效果 亮暗效果
- 让你的table变成exls吧
- 如何利用Python和VC6.0对SQLite数据库进行操作
- 题目1476:平方因子
- 设计模式之工厂模式
- Unity Shader笔记20140322——half4, _Time
- LoopExample改进版
- 数据挖掘学习笔记(4)