D. Black Hills Golden Jewels Two-point answer + two-point decision

Source: Internet
Author: User

Http://codeforces.com/gym/101064/problem/D

The topic is given an array, if 22 combinations, there are C (n, 2) results, (find the result of the first greater than or equal to K)

Ideas

Two-point answer Val, judging as follows.

Sort the array first.

Then violence enumerates each number A[i], then finds the first one greater than val-a[i], the median number and its combination. It's all <=val.

The number of these numbers is counted, if greater than or equal to K is the feasible solution.

Hack

In the two-point answer, the obvious nether is a[1] + a[2]. Upper bound is a[n] + a[n-1]

If you use begin = 1. End = 5e10l is wrong

The begin can be 0

#include <cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#include<assert.h>#defineIOS Ios::sync_with_stdio (False)using namespacestd;#defineINF (0X3F3F3F3F)typedefLong Long intLL; #include<iostream>#include<sstream>#include<vector>#include<Set>#include<map>#include<queue>#include<string>Const intMAXN = 1e5 + -; LL A[maxn];map<ll,int>Book ; LL N, K;BOOLCheck (ll val) {ll total=0;  for(inti =1; I <= N; ++i) {LL dis= Val-A[i]; if(Val <2* A[i]) Break; if(Dis >=A[n]) { Total+ = n-i; } Else {            intpos = Upper_bound (A +1, A +1+ N, dis)-A; Total+ = pos-1-i; }        if(Total >= k)return true; }////cout<< Total << Endl;//if (Total > K) return true;    return false;}voidWork () {IOS; CIN>> N >>K;  for(inti =1; I <= N; ++i) {cin>>A[i]; } sort (A+1, A +1+n);//cout << Check (7) << Endl;LL be = a[1] + a[2]; LL en= A[n] + a[n-1]; ASSERT ( be<=en);//cout << Check (0) << Endl;     while(Be <=en) {LL Mid= (be + en) >>1; if(check (mid)) {en= Mid-1; } Elsebe = mid +1; }//assert (be <= a[n] + a[n-1]);cout << be <<Endl;}intMain () {#ifdef local freopen ("Data.txt","R", stdin);//freopen ("Data.txt", "w", stdout);#endifWork (); return 0;}

D. Black Hills Golden Jewels Two-point answer + two-point decision

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.