This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Problem: Elevator Rides
#include <bits/stdc++.h>
using namespace std ;
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ones(x) __builtin_popcount(x)
#define remove(v) v.erase(unique(all(v)), v.end())
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)
#ifdef local
#include "C:\debug.h"
#else
#define dbg(x...) 42
#endif
const int N = 2e6 + 2 ;
int n , m , a[21] , b[21] , used[21] ;
void go(int i) {
if(i == n + 1) {
cout << "YES\n" ;
exit(0) ;
}
rep(j , 1 , m) {
if(used[j]) continue ;
if(a[i] >= b[j]) {
used[j] = 1 ;
a[i] -= b[j] ;
go(i + (a[i] == 0)) ;
a[i] += b[j] ;
used[j] = 0 ;
}
}
}
void solve(){
cin >> n >> m ;
rep(i , 1 , n) cin >> a[i] ;
rep(i , 1 , m) cin >> b[i] ;
go(1) ;
cout << "NO" ;
}
int main () {
ios::sync_with_stdio(false) ;
cin.tie(0) ;
int test = 1 ;
// cin >> test ;
for(int i = 1 ; i <= test ; i++) {
solve() ;
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |