Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.005 s | 64 KBi |
#include <bits/stdc++.h> #define IO ios_base::sync_with_stdio(false), cin.tie(nullptr) #define endl '\n' using namespace std; long long go(vector<int> &a, vector<int> &b, int k, int l, int i, int j, set<int> &s, long long acum){ if(k<=0)return acum; long long res = 0; s.insert(b[i]); acum += b[i]; if(s.size()>l){acum-=*s.begin();s.erase(s.begin());} res = max(res,a[i]+go(a,b,k-1,l,i+1,j,s,acum)); s.erase(b[i]); acum-=b[i]; s.insert(b[j]); acum += b[j]; if(s.size()>l)s.erase(s.begin()); res = max(res,b[i]+go(a,b,k-1,l,i,j-1,s,acum)); s.erase(b[j]); acum -= b[j]; return res; } int main(){ IO;/* int n;cin>>n; vector<int> a(n+1),b(n+1); for(int i=1;i<=n;i++)cin>>a[i]; for(int i=1;i<=n;i++)cin>>b[i]; int k,l;cin>>k>>l; set<int> s; cout<<go(a,b,k,l,1,n,s,0)<<endl; */ cout<<"Hola Codeo"<<endl; return 0; }