Submission #1609234
Source Code Expand
#include <stdio.h> #include <iostream> #include <vector> #include <algorithm> #include <random> #include <chrono> #include <map> #include <set> #include <numeric> #include <unordered_map> #include <unordered_set> #include <cstring> #include <sstream> #include <queue> using namespace std; using ll = unsigned long long; using triplet = tuple<ll, ll, ll>; using vll = vector<ll>; using vi = vector<int>; using vvi = vector<vi>; int main() { #ifdef LOCAL_TEST freopen("data.txt", "r", stdin); #endif int n, K; scanf("%d %d\n", &n, &K); vi cards(n); for (int i = 0; i < n; ++i) scanf("%d", &cards[i]); sort(cards.begin(), cards.end()); // if any sum of subset between [K-cards[i], K) exists that means this card is unnecessary bitset<5002> sum; sum[0] = 1; int result = n; bool bFound = false; for (int j = n-1; j >= 0 && !bFound; --j) { int c = cards[j]; for (int i = K-c; i >= 0 && i < K; ++i) { if (sum[i]) { result = j; bFound = true; break; } } sum |= sum << c; } printf("%d\n", result); return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - No Need |
User | irfanzaidi |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1266 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:38:5: error: ‘bitset’ was not declared in this scope bitset<5002> sum; ^ ./Main.cpp:38:18: error: ‘sum’ was not declared in this scope bitset<5002> sum; ^ ./Main.cpp:31:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d\n", &n, &K); ^ ./Main.cpp:34:55: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] for (int i = 0; i < n; ++i) scanf("%d", &cards[i]); ^