Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,-1,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define fst first
#define sec second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef unsigned long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define int long long;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);	
}

int main()
{
	//fopen();
	fastio;
	int n,m;
	cin>>n>>m;
	int a[n];
	rep(i,n) cin>>a[i];
	sort(a,a+n);
	int i=0,j=10000000010;
	while(j-i>1)
	{
		int mid=(j+i)/2;
		int cunt=0;
		rep(i,n){ 
			int t=lower_bound(a,a+n,mid-a[i])-a;
			cunt+=n-t;
		}
		//cout<<i<<endl;
		if(cunt>=m)i=mid;
		else j=mid;
	}
	int r[n];
//	cout<<i<<endl;
	rep(j,n) r[j]=a[j]+(j?r[j-1]:0);
	//cout<<r[1]<<endl;
	int ans=0;
	int cnt=0;
	rep(j,n){
		int k=lower_bound(a,a+n,i-a[j])-a;
		ans+=r[n-1]-(k?r[k-1]:0);
		ans+=a[j]*(n-k);
		cnt+=(n-k);
	}
	//cout<<ans<<endl;
	if(cnt>=m)ans-=(cnt-m)*i;
	cout<<ans;
	return 0;
}


Compiler output:
a.cc:18:18: error: declaration does not declare anything [-fpermissive]
   18 | #define int long long;
      |                  ^~~~
a.cc:26:1: note: in expansion of macro 'int'
   26 | int main()
      | ^~~
a.cc:26:5: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   26 | int main()
      |     ^~~~
a.cc: In function 'int main()':
a.cc:18:18: error: declaration does not declare anything [-fpermissive]
   18 | #define int long long;
      |                  ^~~~
a.cc:30:9: note: in expansion of macro 'int'
   30 |         int n,m;
      |         ^~~
a.cc:30:13: error: 'n' was not declared in this scope; did you mean 'yn'?
   30 |         int n,m;
      |             ^
      |             yn
a.cc:30:15: error: 'm' was not declared in this scope; did you mean 'tm'?
   30 |         int n,m;
      |               ^
      |               tm
a.cc:18:18: error: declaration does not declare anything [-fpermissive]
   18 | #define int long long;
      |                  ^~~~
a.cc:32:9: note: in expansion of macro 'int'
   32 |         int a[n];
      |         ^~~
a.cc:32:13: error: 'a' was not declared in this scope; did you mean 'ma'?
   32 |         int a[n];
      |             ^
      |             ma
a.cc:18:18: error: declaration does not declare anything [-fpermissive]
   18 | #define int long long;
      |                  ^~~~
a.cc:3:22: note: in expansion of macro 'int'
    3 | #define rep(i,n) for(int i=0;i<n;i++)
      |                      ^~~
a.cc:33:9: note: in expansion of macro 'rep'
   33 |         rep(i,n) cin>>a[i];
      |         ^~~
a.cc:33:13: error: 'i' was not declared in this scope; did you mean 'vi'?
   33 |         rep(i,n) cin>>a[i];
      |             ^
a.cc:3:26: note: in definition of macro 'rep'
    3 | #define rep(i,n) for(int i=0;i<n;i++)
      |                          ^
a.cc:3:33: error: expected ')' before ';' token
    3 | #define rep(i,n) for(int i=0;i<n;i++)
      |                     ~           ^
a.cc:33:9: note: in expansion of macro 'rep'
   33 |         rep(i,n) cin>>a[i];
      |         ^~~
a.cc:33:13: error: 'i' was not declared in this scope; did you mean 'vi'?
   33 |         rep(i,n) cin>>a[i];
      |             ^
a.cc:3:34: note: in definition of macro 'rep'
    3 | #define rep(i,n) for(int i=0;i<n;i++)
      |                                  ^
a.cc:18:18: error: declaration does not declare anything [-fpermissive]
   18 | #define int long long;
      |                  ^~~~
a.cc:35:9: note: in expansion of macro 'int'
   35 |         int i=0,j=10000000010;
      |         ^~~
a.cc:35:17: error: 'j' was not declared in this scope; did you mean 'jn'?
   35 |         int i=0,j=10000000010;
      |                 ^
      |                 jn
a.cc:18:18: error: declaration does not declare anything [-fpermissive]
   18 | #define int long long;
      |                  ^~~~
a.cc:38:17: note: in expansion of macro 'int'
   38 |                 int mid=(j+i)/2;
      |                 ^~~
a.cc:38:21: error: 'mid' was not declared in this scope
   38 |                 int mid=(j+i)/2;
      |                     ^~~
a.cc:18:18: error: declaration does not declare anything [-fpermissive]
   18 | #define int long long;
      |                  ^~~~
a.cc:39:17: note: in expansion of macro 'int'
   39 |                 int cunt=0;
      |                 ^~~
a.cc:39:21: error: 'cunt' was not declared in this scope
   39 |                 int cunt=0;
      |                     ^~~~
a.cc:18:18: error: declaration does not declare anything [-fpermissive]
   18 | #define int long long;
      |                  ^~~~
a.cc:3:22: note: in expansion of macro 'int'
    3 | #define rep(i,n) for(int i=0;i<n;i++)
      |                      ^~~
a.cc:40:17: note: in expansion of macro 'rep'
   40 |                 rep(i,n){
      |                 ^~~
a.cc:3:33: error: expected ')' before ';' token
    3 | #define rep(i,n) for(int i=0;i<n;i++)
      |                     ~           ^
a.cc:40:17: note: in expansion of macro 'rep'
   40 |                 rep(i,n){
      |                 ^~~
a.cc:18:18: error: declaration does not declare anything [-fpermissive]
   18 | #define int long long;
      |                  ^~~~
a.cc:48:9: note: in expansion of macro 'int'
   48 |         int r[n];
      |         ^~~
a.cc:48:13: error: 'r' was not declared in this scope
   48 |         int r[n];
      |             ^
a.cc:18:18: error: declaration does not declare anything [-fpermissive]
   18 | #define int long long;
      |                  ^~~~
a.cc:3:22: note: in expansion of macro 'int'
    3 | #define rep(i,n) for(int i=0;i<n;i++)
      |                      ^~~
a.cc:50:9: note: in expansion of macro 'rep'
   50 |         rep(j,n) r[j]=a[j]+(j?r[j-1]:0);
      |         ^~~
a.cc:3:33: error: expected ')' before ';' token
    3 | #define rep(i,n) for(int i=0;i<n;i++)
      |                     ~           ^
a.cc:50:9: note: in expansion of macro 'rep'
   50 |         rep(j,n) r[j]=a[j]+(j?r[j-1]:0);
      |         ^~~
a.cc:18:18: error: declaration does not declare anything [-fpermissive]
   18 | #define int long long;
      |                  ^~~~
a.cc:52:9: note: in expansion of macro 'int'
   52 |         int ans=0;
      |         ^~~
a.cc:52:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   52 |         int ans=0;
      |             ^~~
      |             abs
a.cc:18:18: error: declaration does not declare anything [-fpermissive]
   18 | #define int long long;
      |                  ^~~~
a.cc:53:9: note: in expansion of macro 'int'
   53 |         int cnt=0;
      |         ^~~
a.cc:53:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
   53 |         int cnt=0;
      |             ^~~
      |             int
a.cc:18:18: error: declaration does not declare anything [-fpermissive]
   18 | #define int long long;
      |                  ^~~~
a.cc:3:22: note: in expansion of macro 'int'
    3 | #define rep(i,n) for(int i=0;i<n;i++)
      |                      ^~~
a.cc:54:9: note: in expansion of macro 'rep'
   54 |         rep(j,n){
      |         ^~~
a.cc:3:33: error: expected ')' before ';' token
    3 | #define rep(i,n) for(int i=0;i<n;i++)
      |                     ~           ^
a.cc:54:9: note: in expansion of macro 'rep'
   54 |         rep(j,n){
      |         ^~~