# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
469261 | cpp219 | Džumbus (COCI19_dzumbus) | C++14 | 1090 ms | 460 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e3 + 9;
const ll inf = 1e9 + 7;
vector<ll> g[N],dp[2][N],mix[N];
ll n,m,Q,a[N],total,was[N],ans[N],b[N],kq;
LL q[200002];
ll cal(){
ll now = 0,have = 0;
for (ll i = 1;i <= n;i++){
if (!b[i]) continue;
now += a[i];
for (auto node : g[i]){
if (b[node]){
have++; break;
}
}
}
if (now <= total) return have;
return 0;
}
void f(ll i){
if (i > n){
kq = max(kq,cal());
return;
}
b[i] = 1; f(i + 1);
b[i] = 0; f(i + 1);
}
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".ans","w",stdout);
}
cin>>n>>m;
for (ll i = 1;i <= n;i++) cin>>a[i];
while(m--){
ll x,y; cin>>x>>y;
g[x].push_back(y); g[y].push_back(x);
}
cin>>Q;
while(Q--){
cin>>total; kq = 0; f(1);
cout<<kq<<"\n";
}
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
Compilation message (stderr)
# | 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... |