Submission #137873

#TimeUsernameProblemLanguageResultExecution timeMemory
137873MohamedAhmed04Cake 3 (JOI19_cake3)C++14
24 / 100
73 ms64604 KiB
#include <bits/stdc++.h> using namespace std ; const int MAX = 2005 ; long long tmp1[MAX] , tmp2[MAX] , id[MAX] , arr[MAX] , arr2[MAX]; long long dp[MAX][MAX] ; int n , m ; long long solve(int idx , int rem) { if(idx == n && rem != 0) return -1e17 ; if(rem == 0 || idx == n) return 0 ; long long &ret = dp[idx][rem] ; if(ret != -1) return ret ; long long choice1 = solve(idx+1 , rem) ; long long choice2 = solve(idx+1 , rem-1) + arr[idx] ; if(rem != m) choice2 -= id[arr2[idx]] ; if(rem != 1) choice2 += id[arr2[idx]] ; if(rem == 1) choice2 -= id[arr2[idx]] ; if(rem == m) choice2 += id[arr2[idx]] ; ret = max(choice1 , choice2) ; return ret ; } vector< pair<long long , int> >cmprs ; void compress() { sort(cmprs.begin() , cmprs.end()) ; for(int i = 0 ; i < n ; ++i) { arr[i] = tmp1[cmprs[i].second] ; arr2[i] = i ; id[i] = cmprs[i].first; } return ; } int main() { memset(dp , -1 , sizeof(dp)) ; ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n>>m ; for(int i = 0 ; i < n ; ++i) { cin>>tmp1[i]>>tmp2[i] ; cmprs.push_back({tmp2[i] , i}) ; } compress() ; return cout<<solve(0 , m)<<"\n" , 0 ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...