Submission #9263822


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N; ll M; int A[101010];
//---------------------------------------------------------------------------------------------------
ll getCount(int tot) {
	ll res = 0;
	rep(i, 0, N) {
		int Ay = tot - A[i];
		int idx = lower_bound(A, A + N, Ay) - A;
		res += N - idx;
	}
	return res;
}
//---------------------------------------------------------------------------------------------------
ll As[101010];
ll getSum(int tot) {
	rep(i, 0, N) As[i] = A[i];
	rrep(i, N - 2, 0) As[i] += As[i + 1];

	ll res = 0;
	rep(i, 0, N) {
		int Ay = tot - A[i];
		int idx = lower_bound(A, A + N, Ay) - A;
		int cnt = N - idx;
		res += 1LL * A[i] * cnt;
		res += As[idx];
	}
	return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	rep(i, 0, N) cin >> A[i];
	sort(A, A + N);

	int ok = 0, ng = inf;
	while (ok + 1 != ng) {
		int md = (ok + ng) / 2;
		if (M <= getCount(md)) ok = md;
		else ng = md;
	}

	ll ans = (M - getCount(ok + 1)) * ok + getSum(ok + 1);
	cout << ans << endl;
}





Submission Info

Submission Time
Task E - Handshake
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2384 Byte
Status AC
Exec Time 132 ms
Memory 1408 KB

Judge Result

Set Name Sample All after_contest
Score / Max Score 0 / 0 500 / 500 0 / 0
Status
AC × 3
AC × 66
AC
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 100.txt, 101.txt, 102.txt, 103.txt, 104.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, s1.txt, s2.txt, s3.txt
after_contest
Case Name Status Exec Time Memory
01.txt AC 1 ms 256 KB
02.txt AC 1 ms 256 KB
03.txt AC 1 ms 256 KB
06.txt AC 1 ms 256 KB
07.txt AC 101 ms 1280 KB
08.txt AC 41 ms 896 KB
09.txt AC 64 ms 896 KB
10.txt AC 14 ms 384 KB
100.txt AC 1 ms 256 KB
101.txt AC 1 ms 256 KB
102.txt AC 1 ms 256 KB
103.txt AC 1 ms 256 KB
104.txt AC 1 ms 256 KB
11.txt AC 76 ms 1152 KB
12.txt AC 24 ms 640 KB
13.txt AC 115 ms 1408 KB
14.txt AC 97 ms 1408 KB
15.txt AC 111 ms 1408 KB
16.txt AC 111 ms 1408 KB
17.txt AC 93 ms 1408 KB
18.txt AC 119 ms 1408 KB
19.txt AC 104 ms 1408 KB
20.txt AC 83 ms 1408 KB
21.txt AC 118 ms 1408 KB
22.txt AC 107 ms 1408 KB
23.txt AC 89 ms 1408 KB
24.txt AC 103 ms 1280 KB
25.txt AC 108 ms 1408 KB
26.txt AC 91 ms 1280 KB
27.txt AC 126 ms 1408 KB
28.txt AC 108 ms 1408 KB
29.txt AC 79 ms 1280 KB
30.txt AC 100 ms 1280 KB
31.txt AC 96 ms 1408 KB
32.txt AC 82 ms 1408 KB
33.txt AC 96 ms 1408 KB
34.txt AC 90 ms 1408 KB
35.txt AC 86 ms 1408 KB
36.txt AC 95 ms 1408 KB
37.txt AC 91 ms 1408 KB
38.txt AC 82 ms 1408 KB
39.txt AC 84 ms 1408 KB
40.txt AC 93 ms 1408 KB
41.txt AC 77 ms 1408 KB
42.txt AC 81 ms 1408 KB
43.txt AC 87 ms 1280 KB
44.txt AC 77 ms 1408 KB
45.txt AC 81 ms 1280 KB
46.txt AC 82 ms 1280 KB
47.txt AC 78 ms 1280 KB
48.txt AC 87 ms 1408 KB
49.txt AC 94 ms 1408 KB
50.txt AC 76 ms 1408 KB
51.txt AC 86 ms 1408 KB
52.txt AC 97 ms 1408 KB
53.txt AC 72 ms 1408 KB
54.txt AC 89 ms 1408 KB
55.txt AC 132 ms 1408 KB
56.txt AC 92 ms 1408 KB
57.txt AC 87 ms 1408 KB
58.txt AC 93 ms 1408 KB
59.txt AC 89 ms 1408 KB
60.txt AC 89 ms 1408 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB