文章

68

粉丝

691

获赞

26

访问

578.3k

头像
尺取法打卡
P1208
发布于2020年5月20日 12:24
阅读数 6.7k

#include<iostream>
#include<cstdio>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;

#define ll int
#define inf 0x3f3f3f3f
#define MAXN 20005
#define vec vector<ll>

int main() {
	int T, n, a[MAXN], sum[MAXN]; cin >> T;
	while (T--) {
		cin >> n; int sign = 0;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			if (a[i] == 2048) { sign = 1; }
		}
		if (sign) { cout << "YES" << endl; continue; }
		sort(a + 1, a + 1 + n); sum[0] = a[0] = 0;
		for (int i = 1; i <= n; i++)sum[i] = sum[i - 1] + a[i];
		int i = 0, j = 1;
		while (i < n || j < n) {
			int t = sum[j] - sum[i];
			if (t == 2048) { sign = 1; break; }
			else if (t < 2048)j++;
			else i++;
		}
		if (sign) { cout << "YES" << endl; }
		else cout << "NO" << endl;

	}
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发