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