Skip to content

Commit bf1fefb

Browse files
committed
new one
1 parent 844c5aa commit bf1fefb

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

puzzle.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <bits/stdc++.h>
2+
#include <set>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
ios::sync_with_stdio(false);
8+
cin.tie(0);
9+
int arr[10000]={0};
10+
int n,m,t,count=0,min=1200;
11+
cin>>n>>m;
12+
vector <int> puzzles;
13+
for(int i=0;i<m;i++)
14+
{
15+
cin>>t;
16+
++arr[t];
17+
puzzles.push_back(t);
18+
}
19+
for(int i=0;i<50;i++)
20+
{
21+
if(arr[i]>=n) count++;
22+
}
23+
if(count!=0)
24+
cout<<"0";
25+
else
26+
{
27+
int diff;
28+
sort(puzzles.begin(),puzzles.end());
29+
for(int i=0;i<puzzles.size()-n+1;i++)
30+
{
31+
diff=puzzles[n-1+i]-puzzles[i];
32+
if(min>diff)
33+
min=diff;
34+
}
35+
cout<<min;
36+
}
37+
return 0;
38+
}

0 commit comments

Comments
 (0)