이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Dost SEFEROĞLU
#pragma GCC optimize("O3,unroll-loops,Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define vi vector<int>
const int N = 5e2+1,inf = 2e18,MOD = 1e9+7;
void solve() {
int n,m;
cin >> n >> m;
vi a(m+2),b(n+1);
for (int i=1;i<=n;i++) cin >> b[i];
for (int j=1;j<=m;j++) cin >> a[j];
a[m+1] = inf;
int lim = (1<<m);
pii dp[lim];
for (int i=0;i<lim;i++) {
dp[i] = {-1,0};
}
dp[0] = {0,-b[1]};
for (int i=1;i<lim;i++) {
for (int j=0;j<m;j++) {
if (!(i&(1<<j))) continue;
int rem = i^(1<<j);
if (dp[rem].second+a[j+1] > 0) continue;
else if (dp[rem].second+a[j+1] == 0){
dp[i] = max(dp[i],{dp[rem].ff+1,-b[dp[rem].ff+2]});
}
else dp[i] = max(dp[i],{dp[rem].first,dp[rem].second+a[j+1]});
}
}
auto it = max_element(dp,dp+lim);
cout << it->ff sp it->ss << '\n';
cout << (it->ff == n ? "YES\n" : "NO\n");
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) 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... |