简单题
View Code
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <cmath> using namespace std; #define maxn 50005 int t, n; int f[maxn]; bool cmp(const int &a, const int &b) { return abs(a) < abs(b); } void input() { scanf("%d%d", &t, &n); for (int i = 0; i < n; i++) scanf("%d", &f[i]); } int work() { int ret = 0; int temp = 0; int left = t; while (abs(temp - f[ret]) < left) { left -= abs(temp - f[ret]); temp = f[ret]; ret++; } return ret; } int main() { //freopen("t.txt", "r", stdin); input(); sort(f, f + n, cmp); printf("%d\n", work()); return 0; }