Submission #656011

#TimeUsernameProblemLanguageResultExecution timeMemory
656011iskhakkutbilimBank (IZhO14_bank)C++17
44 / 100
1076 ms420 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define all(a) a.begin(), a.end() const int M = 1e9 + 7; const int N = 1e6 + 1; main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; int a[n], b[m]; vector<int> g[n]; for(int i = 0;i < n; i++){ cin >> a[i]; } for(int i = 0;i < m; i++){ cin >> b[i]; } sort(b, b + m); for(int mask = 0; mask < (1<<m); mask++){ int sum = 0; for(int i = 0;i < m; i++){ if(mask & (1<<i)){ sum+= b[i]; } } for(int i = 0;i < n; i++){ if(a[i] == sum){ g[i].push_back(mask); } } } if(n == 1){ if(g[0].empty()) cout << "NO"; else cout << "YES"; }else{ do{ int cur_sum = 0, idx = 0; for(int i = 0;i < m; i++){ if(idx >= n) break; cur_sum+= b[i]; if(cur_sum == a[idx]){ idx++, cur_sum = 0; } } if(idx >= n){ cout << "YES"; return 0; } }while(next_permutation(b, b + m)); cout << "NO"; } return 0; }

Compilation message (stderr)

bank.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...