#include<bits/stdc++.h>
using namespace std;
int b[30];
int main(){
int cnt,w[30],c[30],n,m,s,z,maxx=0;
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>w[i]>>c[i];
}
while(b[0]!=1){
s=0,z=0,cnt=m;
for(int i=1;i<=m;i++){
s+=b[i]*w[i];
z+=b[i]*c[i]*w[i];
}
if(s<=n&&z>maxx){
maxx=z;
}
if(b[n]==0){
b[n]=1;
}
else{
while(b[cnt]==1){
b[cnt]=0;
cnt--;
}
b[cnt]=1;
}
}
cout<<maxx;
return 0;
}
为啥全是RE,样例全过了?