美文网首页
poj3618 模拟(数轴)

poj3618 模拟(数轴)

作者: 暖昼氤氲 | 来源:发表于2019-12-01 19:51 被阅读0次
 /*
Time:2019.12.1
Author: Goven
type:模拟(数轴) 
err:
ref:
*/
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int a[50005];

bool cmp(int x, int y) {
    return abs(x) < abs(y); 
}

int main()
{
    int t, n;
    cin >> t >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n, cmp);
    int pos, sum, i;
    pos = sum = i = 0;
    while (i < n && sum < t) {
        sum += abs(pos - a[i]);
        pos = a[i];
        i++;
    }
    i--;
    cout << i << endl;
    return 0;
}


相关文章

网友评论

      本文标题:poj3618 模拟(数轴)

      本文链接:https://www.haomeiwen.com/subject/kmktgctx.html