Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- //#include <emmintrin.h>
- using namespace std;
- #define FORE(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
- #define FOR(i,a,b) for(int i=(a);i<(b);++i)
- #define REP(i,a) FOR(i,0,a)
- #define ZERO(m) memset(m,0,sizeof(m))
- #define ALL(x) x.begin(),x.end()
- #define PB push_back
- #define S size()
- #define LL long long
- #define ULL unsigned long long
- #define LD long double
- #define MP make_pair
- #define X first
- #define Y second
- #define VC vector
- #define PII pair <int, int>
- #define VI VC < int >
- #define VVI VC < VI >
- #define VD VC < double >
- #define VVD VC < VD >
- #define VS VC < string >
- #define DB(a) cerr << #a << ": " << (a) << endl;
- template<class T> void print(VC < T > v) {cerr << "[";if (v.S) cerr << v[0];FOR(i, 1, v.S) cerr << ", " << v[i];cerr << "]\n";}
- template<class T> string i2s(T x) {ostringstream o; o << x; return o.str(); }
- VS splt(string s, char c = ' ') {VS all; int p = 0, np; while (np = s.find(c, p), np >= 0) {if (np != p) all.PB(s.substr(p, np - p)); p = np + 1;} if (p < s.S) all.PB(s.substr(p)); return all;}
- unsigned int dp[1<<24];
- unsigned int a[24];
- unsigned int c[100];
- const unsigned int MAXW = 1<<27;
- const unsigned int MAX_INT = -1;
- int main() {
- int n, m;
- cin >> n >> m;
- REP(i, n) cin >> a[i];
- REP(i, m) cin >> c[i];
- sort(c, c + m);
- reverse(c, c + m);
- memset(dp, 0xFF, sizeof(dp));
- dp[0] = 0;
- REP(i, 1<<n) {
- if (dp[i] == MAX_INT) continue;
- unsigned int x = dp[i] >> 27;
- unsigned int w = dp[i] & (MAXW-1);
- REP(j, n) if ((i & (1 << j)) == 0) {
- unsigned int z = w + a[j] > c[x] ? (a[j] > c[x+1] ? MAX_INT : ((x+1)<<27)+a[j]) : (x<<27)+w+a[j];
- dp[i+(1<<j)] = min(dp[i+(1<<j)], z);
- }
- }
- int r = ((dp[(1<<n)-1]/MAXW)+1);
- if (r == 32) cout << "NIE"; else cout << r;
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement