Submission #315903

#TimeUsernameProblemLanguageResultExecution timeMemory
315903TrungNotChungJelly Flavours (IOI20_jelly)C++17
100 / 100
294 ms172664 KiB
//TrungNotChung #include <iostream> #include <bits/stdc++.h> #include <queue> #include <set> #define foru(i,a,b) for(int i=a ; i<=b ; ++i) #define ford(i,a,b) for(int i=b ; i>=a ; --i) #define pii pair<int,int> #define fi first #define se second #define oo (int)1e9 #define __builtin_popcount __builtin_popcountll using namespace std; const int N = 2000; const int M = 10000; struct Jelly { int a , b; bool operator < (const Jelly &x) { return a < x.a; } }f[N]; int dp[N+1][M+1]; int suf[N+1][N+1] , num[N+1][M+1]; int n , w1 , w2; int find_maximum_unique(int w1 , int w2 , vector<int>a1 , vector<int>b1) { n = a1.size(); for(int i=0 ; i<n ; ++i) { f[i+1].a = a1[i]; f[i+1].b = b1[i]; } sort(f+1 , f+n+1); for(int i=1 ; i<=n ; ++i) for(int j=1 ; j<=n ; ++j) suf[i][j] = oo; for(int i=n ; i>=1 ; --i) { for(int j=1 ; j<=(n-i+1) ; ++j) { if(i==n) { suf[i][j] = f[i].b; } else { suf[i][j] = min(suf[i+1][j] , suf[i+1][j-1]+f[i].b); } if(suf[i][j] <= M) num[i][suf[i][j]] = max(num[i][suf[i][j]] , j); } for(int j=1 ; j<=M ; ++j) num[i][j] = max(num[i][j-1] , num[i][j]); } int ans = 0; for(int i=1 ; i<=n ; ++i) { for(int j=0 ; j<=w1 ; ++j) { dp[i][j] = dp[i-1][j]+f[i].b; if(j>=f[i].a) dp[i][j] = min(dp[i-1][j-f[i].a] , dp[i][j]); if(dp[i][j] <= w2) { ans = max(ans , i+num[i+1][w2-dp[i][j]]); } } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...