记录编号 |
425866 |
评测结果 |
AAAAAAAAAAA |
题目名称 |
[NOIP 2007]纪念品分组 |
最终得分 |
100 |
用户昵称 |
HeHe |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.009 s |
提交时间 |
2017-07-16 07:14:39 |
内存使用 |
0.62 MiB |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAXN (30010)
inline char getc(void) {
static char buf[1 << 18], *fs, *ft;
return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}
inline int read(void) {
register int res = 0;
register char tmp = getc();
while(!isdigit(tmp)) tmp = getc();
while(isdigit(tmp))
res = ((res + (res << 2)) << 1) + (tmp ^ 0x30),
tmp = getc();
return res;
}
int W, N, cnt;
int l, r, temp;
int s[MAXN];
int main() {
#ifndef LOCAL
freopen("group.in", "r", stdin);
freopen("group.out", "w", stdout);
#endif
W = read(), r = (N = read()) - 1;
for(int i = 0, *t = s; i < N; ++i, ++t) *t = read();
sort(s, s + N);
while(s[r] > W) --r;
while(l <= r) {
if(s[l] + s[r] <= W) ++l;
--r;
++cnt;
}
printf("%d\n", cnt);
}