diff --git a/Debugs-and-Optimizations/Task1/solution.cpp b/Debugs-and-Optimizations/Task1/solution.cpp index 4b7af6a..1a72ce3 100644 --- a/Debugs-and-Optimizations/Task1/solution.cpp +++ b/Debugs-and-Optimizations/Task1/solution.cpp @@ -4,54 +4,53 @@ using namespace std; #define sz(x) ((long long)(x).size()) #define vl vector -#include -using namespace __gnu_pbds; -typedef tree, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset; -// *s.find_by_order, *s.order_of_key --> O(logn) -void myerase(indexed_multiset &t, int v){ - int rank = t.order_of_key(v); - indexed_multiset::iterator it = t.find_by_order(rank); - t.erase(it); -} - -ll n,k; -int ans; - -void func(ll i,vl &a,indexed_multiset &s){ - if(i>=sz(a)) return; - if(i==sz(a)-1) - { - s.insert(a[i]); - ll n=sz(s); - ans = max(ans,*s.find_by_order((n+1)/2 -1)); - myerase(s,a[i]); +int n, k; - if(k==1){ - n=sz(s); - ans = max(ans,*s.find_by_order((n+1)/2 -1)); +bool check(ll m,vl &a,vl &dp,vl &b) { + for(ll i=0;i=m){ + b[i]=1; + } + else{ + b[i]=-1; } - return; } - //choose cur - s.insert(a[i]); - func(i+1,a,s); - myerase(s,a[i]); - - //choose after removing - func(i+k,a,s); + dp[0] = b[0]; + for(ll i=1;ik){ + dp[i]=max(dp[i],dp[i-k]); + } + } + } + return dp[n-1] > 0; } + void solve() { cin>>n>>k; vl a(n); - for(ll i=0;i>a[i]; } - indexed_multiset s; - func(0,a,s); - cout<