Submission #157223

#TimeUsernameProblemLanguageResultExecution timeMemory
157223manh9203스트랩 (JOI14_straps)C++17
95 / 100
249 ms32252 KiB
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") #define fi first #define se second const int N = 2e3 + 5; long long n,dp[N][N],rmq[N][20]; pair<long long,long long> rope[N]; long long get(int l,int r){ int k = log2(r - l + 1); return max(rmq[l][k], rmq[r-(1<<k)+1][k]); } 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=0;i<=n;i++) rmq[i][0] = dp[0][i]; for(int j=1;(1<<j)<=n;j++){ for(int i=0;i+(1<<j)-1<=n;j++){ rmq[i][j] = max(rmq[i][j-1], rmq[i+(1<<(j-1))][j-1]); } } for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ dp[i][j] = max(dp[i-1][j], get(j - 1, min(n, j + rope[i].fi - 1)) + rope[i].se); } for(int j=0;j<=n;j++){ rmq[j][0] = dp[i][j]; } for(int k=1;(1<<k)<=n;k++){ for(int j=0;j+(1<<k)-1<=n;j++){ rmq[j][k] = max(rmq[j][k-1], rmq[j+(1<<(k-1))][k-1]); } } } 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...