记录编号 |
394055 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[HAOI 2012]音量调节 |
最终得分 |
100 |
用户昵称 |
HeHe |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.003 s |
提交时间 |
2017-04-12 20:56:13 |
内存使用 |
0.37 MiB |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN1 = 1010;
const int MAXN2 = 60;
inline int in(void){
char tmp = getchar();
int res = 0;
while(!isdigit(tmp))tmp = getchar();
while(isdigit(tmp))
res = (res + (res << 2) << 1) + (tmp ^ 48),
tmp = getchar();
return res;
}
int N, maxLevel, beginLevel, tmp;
bool f[MAXN2][MAXN1];
int main(){
#ifndef LOCAL
freopen("changingsounds.in", "r", stdin);
freopen("changingsounds.out", "w", stdout);
#else
freopen("test.in", "r", stdin);
#endif
N = in(), beginLevel = in(), maxLevel = in();
f[0][beginLevel] = true;
for(int i = 1; i <= N; ++i){
tmp = in();
for(int j = 0; j <= maxLevel; ++j){
if(j >= tmp)f[i][j] = f[i - 1][j - tmp];
if(!f[i][j] && j + tmp <= maxLevel)f[i][j] = f[i - 1][j + tmp];
}
}
for(int i = maxLevel; i > 0; --i){
if(f[N][i]){
printf("%d\n", i);
return 0;
}
}
printf("-1\n");
return 0;
}