結果

問題 No.615 集合に分けよう
ユーザー SmitMangukiya
提出日時 2020-11-10 15:44:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 723 bytes
コンパイル時間 1,419 ms
コンパイル使用メモリ 168,980 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-22 17:32:14
合計ジャッジ時間 3,201 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 2
other AC * 11 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
   fast;
   int n,k;
   cin >> n >> k;
   int a[n];
   f(i,0,n) cin >> a[i];
   sort(a, a+n);
   int size = n - k + 1;
   int ans = min(a[size-1] - a[0], a[n-1] - a[n-size]);
   cout << ans << "\n";
}
0