Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <list>
- #include <map>
- #include <set>
- #include <deque>
- #include <stack>
- #include <queue>
- #include <algorithm>
- #include <sstream>
- #include <iostream>
- #include <iomanip>
- #include <cstdio>
- #include <cmath>
- #include <cstdlib>
- #include <memory.h>
- #include <ctime>
- #include <bitset>
- using namespace std;
- #define ABS(a) ((a>0)?a:-(a))
- #define MIN(a,b) ((a<b)?(a):(b))
- #define MAX(a,b) ((a<b)?(b):(a))
- #define FOR(i,a,n) for (int i=(a);i<(n);++i)
- #define FI(i,n) for (int i=0; i<(n); ++i)
- #define pnt pair <int, int>
- #define mp make_pair
- #define PI 3.14159265358979
- #define MEMS(a,b) memset(a,b,sizeof(a))
- #define LL long long
- #define U unsigned
- int was[110][200100];
- int n,t;
- int a[110];
- void dfs(int p, int sum)
- {
- if (was[p][sum]==t)
- return;
- was[p][sum]=t;
- if (p==n)
- return;
- dfs(p+1,sum+a[p]);
- dfs(p+1,sum);
- }
- int main()
- {
- #ifdef Fcdkbear
- freopen("in.txt","r",stdin);
- //freopen("out.txt","w",stdout);
- double beg=clock();
- #endif
- int num;
- scanf("%d",&num);
- for (t=1; t<=num; ++t)
- {
- int A;
- scanf("%d%d",&n,&A);
- int sum=0;
- FOR(i,0,n)
- {
- scanf("%d",&a[i]);
- sum+=a[i];
- }
- dfs(0,0);
- bool is=false;
- FOR(i,A/2,sum+1)
- if ((was[n][i]==t) && (i+i>=A))
- {
- is=true;
- printf("%d\n",i);
- break;
- }
- if (!is)
- printf("-1\n");
- }
- #ifdef Fcdkbear
- double end=clock();
- fprintf(stderr,"*** Total time = %.3lf ***\n",(end-beg)/CLOCKS_PER_SEC);
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment