CodeForces 337A - Puzzles

603 단어 codeforces
어떻게 dp를 사용합니까?수학을 했어요...
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
	int n,m;
	int arr[55];
	cin>>n>>m;
	for(int i=0;i<m;++i)
		cin>>arr[i];
	sort(arr,arr+m);
	int tmp=1000000;
	for(int i=n-1;i<m;++i)
	{
         if(tmp>arr[i]-arr[i-n+1])
         {
         	//cout<<arr[i]<<" "<<arr[i-n+1]<<endl;
         	tmp=arr[i]-arr[i-n+1];
         	//cout<<tmp<<endl;
         }
         	

	}
	cout<<tmp<<endl;
	return 0;
}

좋은 웹페이지 즐겨찾기