Title Link: Http://codeforces.com/gym/101064/problem/D
Ask you how many of the K-plus numbers are added to the two-number combination.
First sort array, two-point answer, and then judge its correctness (the judgment process is to enumerate each number and then two minutes).
1 //#pragma COMMENT (linker, "/stack:102400000, 102400000")2#include <algorithm>3#include <iostream>4#include <cstdlib>5#include <cstring>6#include <cstdio>7#include <vector>8#include <cmath>9#include <ctime>Ten#include <list> One#include <Set> A#include <map> - using namespacestd; -typedefLong LongLL; thetypedef pair <int,int>P; - Const intN = 1e5 +5; - LL A[n], K, N; - + BOOLjudge (LL val) { -LL cnt =0; + for(inti =1; I <= N; ++i) { All pos = (ll) (Upper_bound (A +1, A + n +1, Val-a[i])-a); at if(Pos >(LL) i) -CNT + = N-pos +1; - Else -CNT + = n-Pos; - } -CNT/=2; in return(N-1) *n/2-K >=CNT; - } to + intMain () - { the while(~SCANF ("%lld%lld", &n, &k)) { * for(inti =1; I <= N; ++i) { $scanf"%lld", A +i);Panax Notoginseng } -Sort (A +1, A + n +1); theLL L = a[1] + a[2], r = a[n] + a[n-1]; + while(L <r) { ALL mid = (L + r)/2; the if(judge (mid)) { +R =mid; -}Else { $L = mid +1; $ } - } -printf"%lld\n", L); the } - return 0;Wuyi}
Gym 101064 D Black Hills Golden Jewels (two minutes)