# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
586776 |
2022-06-30T17:00:53 Z |
BhavayGoyal |
Bank (IZhO14_bank) |
C++14 |
|
1000 ms |
304 KB |
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define ld long double
#define ar array
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
const int MOD = 1e9+7;
const int inf = 1e9;
const ll linf = 1e18;
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
// -------------------------------------------------- Main Code --------------------------------------------------
int a[20], b[20];
int n, m;
pii sol(int mask) {
if (mask == 0) return {0, 0};
pii ans = {0, 0};
for (int i = 0; i < m; i++) {
if (mask&(1<<i)) {
pii x = sol(mask^(1<<i));
int prevPer = x.f;
int left = x.s;
if (left+b[i] == a[prevPer]) prevPer++, left = 0;
else if (left+b[i] < a[prevPer]) left += b[i];
ans = max(ans, {prevPer, left});
}
}
return ans;
}
void sol() {
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
for (int i = 0; i < (1<<m); i++) {
if (sol(i).f == n) {
cout << "YES" << endl;
return;
}
}
cout << "NO" << endl;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
sol();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Execution timed out |
1074 ms |
212 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
364 ms |
300 KB |
Output is correct |
2 |
Correct |
359 ms |
300 KB |
Output is correct |
3 |
Correct |
335 ms |
212 KB |
Output is correct |
4 |
Correct |
346 ms |
212 KB |
Output is correct |
5 |
Correct |
355 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
341 ms |
304 KB |
Output is correct |
8 |
Correct |
386 ms |
300 KB |
Output is correct |
9 |
Correct |
339 ms |
300 KB |
Output is correct |
10 |
Correct |
345 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Execution timed out |
1074 ms |
212 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |