记录编号 425865 评测结果 AAAAAAAAAA
题目名称 [POI 1997] 独木舟 最终得分 100
用户昵称 GravatarHeHe 是否通过 通过
代码语言 C++ 运行时间 0.011 s
提交时间 2017-07-16 06:57:51 内存使用 0.68 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("kaj.in", "r", stdin);
    freopen("kaj.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);
}