Submission #3741193


Source Code Expand

Copy
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

typedef long long ll;
using namespace std;

int main() {
    
    int n, k;
    cin >> n >> k;
    
    vector<int> h(n, 0);
    for (int i = 0; i < n; i++)
        cin >> h[i];
    
    sort(h.begin(), h.end());
    
    int ans = 0x7FFFFFFF;
    for (int i = 0; i + k - 1 < n; i++) {
        ans = min(ans, h[i + k - 1] - h[i]);
    }
    
    cout << ans << endl;
    
}

Submission Info

Submission Time
Task C - Christmas Eve
User ganmodokix
Language C++14 (GCC 5.4.1)
Score 300
Code Size 535 Byte
Status AC
Exec Time 47 ms
Memory 640 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 10
Set Name Test Cases
Sample a01, a02
All a01, a02, b03, b04, b05, b06, b07, b08, b09, b10
Case Name Status Exec Time Memory
a01 AC 2 ms 256 KB
a02 AC 2 ms 256 KB
b03 AC 2 ms 256 KB
b04 AC 46 ms 640 KB
b05 AC 47 ms 640 KB
b06 AC 47 ms 640 KB
b07 AC 47 ms 640 KB
b08 AC 47 ms 640 KB
b09 AC 47 ms 640 KB
b10 AC 47 ms 640 KB