CF#196DIV2:A-Puzzles

http://codeforces.com/contest/337/problem/A

The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for hern students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).

The shop assistant told the teacher that there are m puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists off1 pieces, the second one consists off2 pieces and so on.

Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. LetA be the number of pieces in the largest puzzle that the teacher buys andB be the number of pieces in the smallest such puzzle. She wants to choose suchn puzzles that A - B is minimum possible. Help the teacher and find the least possible value ofA - B.

Input

The first line contains space-separated integers n andm (2 ≤ n ≤ m ≤ 50). The second line containsm space-separated integers f1, f2, ..., fm (4 ≤ fi ≤ 1000) — the quantities of pieces in the puzzles sold in the shop.

Output

Print a single integer — the least possible difference the teacher can obtain.

Sample test(s)
Input
4 6
10 12 10 7 5 22
Output
5
Note

Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.


 

题意:给出n,m,n是学生数,m是礼物数,在m哥礼物中 找出n个礼物,是的最大与最小值得差最小

思路:由于数据小,直接排序暴力

 

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,m,i,a[55],Min,s;
    while(~scanf("%d%d",&m,&n))
    {
        for(i = 0; i<n; i++)
            scanf("%d",&a[i]);
        sort(a,a+n);
        Min = 10000;
        m = m-1;
        for(i = m; i<n; i++)
        {
            s = a[i]-a[i-m];
            if(s<Min)
                Min = s;
        }
        printf("%d\n",Min);
    }

    return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的游戏网站框架,包含HTML和CSS代码: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Game Website</title> <style> /* CSS代码 */ body { background-color: #f2f2f2; font-family: Arial, sans-serif; margin: 0; padding: 0; } .container { width: 80%; margin: 0 auto; padding: 20px; background-color: #fff; box-shadow: 0px 0px 10px 0px #ccc; } h1 { font-size: 36px; text-align: center; margin-top: 0; padding-top: 20px; } nav { background-color: #333; color: #fff; padding: 10px; margin-bottom: 20px; } nav ul { list-style: none; margin: 0; padding: 0; display: flex; justify-content: space-between; } nav ul li { margin: 0; padding: 0; } nav ul li a { color: #fff; text-decoration: none; font-size: 18px; padding: 10px; } nav ul li a:hover { background-color: #666; } footer { background-color: #333; color: #fff; padding: 10px; text-align: center; margin-top: 20px; } </style> </head> <body> <div class="container"> <header> <h1>Game Website</h1> <nav> <ul> <li><a href="#">Home</a></li> <li><a href="#">Games</a></li> <li><a href="#">About Us</a></li> <li><a href="#">Contact Us</a></li> </ul> </nav> </header> <main> <p>Welcome to our game website!</p> <p>Here you can find a variety of games to play, from action-packed shooters to mind-boggling puzzles.</p> <p>Check out our <a href="#">Games</a> page to see what's available.</p> </main> <footer> <p>© 2021 Game Website. All rights reserved.</p> </footer> </div> </body> </html> ``` 这个框架包含一个容器(`.container`)来包含页面内容,一个页眉(`header`),一个导航栏(`nav`),一个主要内容区域(`main`),以及一个页脚(`footer`)。 CSS代码定义了页面的样式,包括页面背景颜色、字体、边距、阴影、标题、导航栏、链接等。 需要注意的是,这只是一个简单的框架,可以根据实际需要进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值