Submission #157220

#TimeUsernameProblemLanguageResultExecution timeMemory
157220manh9203스트랩 (JOI14_straps)C++17
50 / 100
38 ms31864 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second const int N = 2e3 + 5; long long n,dp[N][N]; pair<long long,long long> rope[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i=1;i<=n;i++) cin >> rope[i].fi >> rope[i].se; for(int i=0;i<=n;i++){ for(int j=1;j<=n;j++){ dp[i][j] = -1e18; } } sort(rope+1, rope+1+n); for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ dp[i][j] = max(dp[i-1][min((long long)i-1, j + rope[i].fi - 1)], dp[i-1][j-1]) + rope[i].se; dp[i][j] = max(dp[i][j], dp[i-1][j]); } } cout << max(dp[n][0], dp[n][1]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...