結果
| 問題 |
No.156 キャンディー・ボックス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-12-15 00:04:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,611 bytes |
| コンパイル時間 | 1,435 ms |
| コンパイル使用メモリ | 169,808 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-20 00:59:15 |
| 合計ジャッジ時間 | 2,525 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 14 WA * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct Scanner {
public:
explicit Scanner(FILE *fp) : fp(fp) {}
template< typename T, typename... E >
void read(T &t, E &... e) {
read_single(t);
read(e...);
}
private:
static constexpr size_t line_size = 1 << 16;
static constexpr size_t int_digits = 20;
char line[line_size + 1] = {};
FILE *fp = nullptr;
char *st = line;
char *ed = line;
void read() {}
static inline bool is_space(char c) {
return c <= ' ';
}
void reread() {
ptrdiff_t len = ed - st;
memmove(line, st, len);
char *tmp = line + len;
ed = tmp + fread(tmp, 1, line_size - len, fp);
*ed = 0;
st = line;
}
void skip_space() {
while(true) {
if(st == ed) reread();
while(*st && is_space(*st)) ++st;
if(st != ed) return;
}
}
template< typename T, enable_if_t< is_integral< T >::value, int > = 0 >
void read_single(T &s) {
skip_space();
if(st + int_digits >= ed) reread();
bool neg = false;
if(is_signed< T >::value && *st == '-') {
neg = true;
++st;
}
typename make_unsigned< T >::type y = *st++ - '0';
while(*st >= '0') {
y = 10 * y + *st++ - '0';
}
s = (neg ? -y : y);
}
template< typename T, enable_if_t< is_same< T, string >::value, int > = 0 >
void read_single(T &s) {
s = "";
skip_space();
while(true) {
char *base = st;
while(*st && !is_space(*st)) ++st;
s += string(base, st);
if(st != ed) return;
reread();
}
}
template< typename T >
void read_single(vector< T > &s) {
for(auto &d : s) read(d);
}
};
struct Printer {
public:
explicit Printer(FILE *fp) : fp(fp) {}
~Printer() { flush(); }
template< bool f = false, typename T, typename... E >
void write(const T &t, const E &... e) {
if(f) write_single(' ');
write_single(t);
write< true >(e...);
}
template< typename... T >
void writeln(const T &...t) {
write(t...);
write_single('\n');
}
void flush() {
fwrite(line, 1, st - line, fp);
st = line;
}
private:
FILE *fp = nullptr;
static constexpr size_t line_size = 1 << 16;
static constexpr size_t int_digits = 20;
char line[line_size + 1] = {};
char small[32] = {};
char *st = line;
template< bool f = false >
void write() {}
void write_single(const char &t) {
if(st + 1 >= line + line_size) flush();
*st++ = t;
}
template< typename T, enable_if_t< is_integral< T >::value, int > = 0 >
void write_single(T s) {
if(st + int_digits >= line + line_size) flush();
if(s == 0) {
write_single('0');
return;
}
if(s < 0) {
write_single('-');
s = -s;
}
char *mp = small + sizeof(small);
typename make_unsigned< T >::type y = s;
size_t len = 0;
while(y > 0) {
*--mp = y % 10 + '0';
y /= 10;
++len;
}
memmove(st, mp, len);
st += len;
}
void write_single(const string &s) {
for(auto &c : s) write_single(c);
}
void write_single(const char *s) {
while(*s != 0) write_single(*s++);
}
template< typename T >
void write_single(const vector< T > &s) {
for(size_t i = 0; i < s.size(); i++) {
if(i) write_single(' ');
write_single(s[i]);
}
}
};
int main() {
Scanner in(stdin);
Printer out(stdout);
int N, M;
in.read(N, M);
int c[10];
for (int i = 0; i < N; i++) {
in.read(c[i]);
}
sort(c, c + N);
int sum = 0;
for (int i = 0; i < N; i++) {
sum += c[i];
if (sum > M) {
out.writeln(i);
break;
}
}
return 0;
}