Cf386B
来源:互联网 发布:淘宝女士连衣裙 编辑:程序博客网 时间:2024/05/17 04:21
/*B - Fly, freebies, fly!Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64uSubmit Status Practice CodeForces 386BDescriptionEveryone loves a freebie. Especially students.It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" — then flown freebie helps him to pass the upcoming exam.In the night before the exam on mathematical analysis n students living in dormitory shouted treasured words. The i-th student made a sacrament at the time ti, where ti is the number of seconds elapsed since the beginning of the night.It is known that the freebie is a capricious and willful lady. That night the freebie was near dormitory only for T seconds. Therefore, if for two students their sacrament times differ for more than T, then the freebie didn't visit at least one of them.Since all students are optimists, they really want to know what is the maximal number of students visited by the freebie can be.InputThe first line of the input contains integer n (1 ≤ n ≤ 100), where n — the number of students shouted "Fly, freebie, fly!" The second line contains n positive integers ti (1 ≤ ti ≤ 1000).The last line contains integer T (1 ≤ T ≤ 1000) — the time interval during which the freebie was near the dormitory.OutputPrint a single integer — the largest number of people who will pass exam tomorrow because of the freebie visit.Sample InputInput64 1 7 8 3 81Output3By Grant Yuan2014.7.11*/#include<iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>using namespace std;int n,T,t[102],sum[102];int cmp(const void *a,const void *b){ return(*(int*)a-*(int*)b);}int main(){ cin>>n; memset(sum,0,102); for(int i=0;i<n;i++) cin>>t[i]; cin>>T; qsort(t,n,sizeof(t[0]),cmp); for(int i=0;i<n;i++) for(int j=i;j<n;j++) if(t[i]+T>=t[j]) sum[i]++; int max=sum[0]; for(int i=0;i<n;i++) if(sum[i]>max) max=sum[i]; cout<<max<<endl; return 0;}
0 0
- Cf386B
- python 十进制与二进制以及位运算
- VS C++ MethodInvoker 倒数计时器
- 2013 长沙邀请赛 ADEGH 题解
- 如何让平滑细分只平滑一个物体的一部分,而其他部分不受影响
- java 线程 原子类相关操作示例 thinking in java4 目录21.3.4
- Cf386B
- LeetCode -- sameTree
- C/C++内存分配
- 黑马程序员_反射
- Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
- 幸福资本信用卡客户群
- Cf387A
- 研发之道(8)架构设计漫谈(三)时钟和复位
- Cf393A