记录编号 310822 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 从零开始的生存时间 最终得分 100
用户昵称 Gravatar沉迷学习的假的Keller 是否通过 通过
代码语言 C++ 运行时间 30.526 s
提交时间 2016-09-23 15:08:16 内存使用 53.62 MiB
显示代码纯文本
  1. #include<algorithm>
  2. #include<cassert>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<iostream>
  6. #include<string>
  7. #include<vector>
  8. using namespace std;
  9. const int maxn=10000000+10;
  10. int n,m;
  11. long long a[maxn],ans,k;
  12. inline void read(long long &x){
  13. char ch;
  14. while(ch=getchar(),ch<48||ch>57);
  15. x=ch-48;
  16. while(ch=getchar(),ch>47&&ch<58)x=x*10+ch-48;
  17. }
  18. int MAIN(){
  19. freopen("Re_Rest.in","r",stdin);
  20. freopen("Re_Rest.out","w",stdout);
  21. scanf("%d",&n);
  22. for(int i=1;i<=n;i++){
  23. read(a[i]);
  24. }
  25. sort(a+1,a+n+1);
  26. scanf("%d",&m);
  27. for(int i=1;i<=m;i++){
  28. ans=0;
  29. read(k);
  30. int l=1,r=n;
  31. while(l<r){
  32. if(k<(a[l]+a[r])){
  33. r--;
  34. }
  35. else{
  36. ans+=r-l;
  37. l++;
  38. }
  39. }
  40. printf("%lld\n",ans);
  41. }
  42. }
  43. int main(){;}
  44. int helenkeller=MAIN();