Skip to content

Commit 2141270

Browse files
committed
337A
1 parent 7753a33 commit 2141270

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.in
2+
*.out

337A Puzzles.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
int main() {
8+
int n, m;
9+
cin >> n >> m;
10+
vector<int> a;
11+
int crnt;
12+
for (int t=0; t<m; ++t) {
13+
cin >> crnt;
14+
a.push_back(crnt);
15+
}
16+
17+
sort(a.begin(), a.end());
18+
19+
int ans = INT_MAX;
20+
for (int i=0; i+n<=a.size(); ++i)
21+
ans = min(ans, a[i+n-1]-a[i]);
22+
cout << ans << endl;
23+
return 0;
24+
}

0 commit comments

Comments
 (0)