Submission #1227641
Source Code Expand
#include <bits/stdc++.h> #define N 3010 #define INF 1e9 using namespace std; typedef pair<int,int> P; typedef pair<P,int> PP; void Max(int &a,int b){a=max(a,b);} int dp[N][N]; int main(){ int n,H[N]; cin>>n; for(int i=0;i<n;i++)cin>>H[i]; vector<PP> A(n); for(int i=0,m,s,e;i<n;i++)cin>>m>>s>>e,A[i] = PP(P(e,s),m); sort(A.begin(),A.end()); for(int i=0;i<N;i++)for(int j=0;j<N;j++) dp[i][j] = -INF; dp[0][0] = 0; for(int i=0;i<n;i++){ int r = A[i].first.first; int l = A[i].first.second; int m = A[i].second; int a,b; for(a=i+1;a<n&&r>A[a].first.second;a++); for(b=i+1;b<n&&(r>A[b].first.second||A[b].second!=m);b++); for(int j=0;j<n;j++){ Max(dp[i+1][0],dp[i][j]); Max(dp[a][0],dp[i][j]+H[j]); Max(dp[b][j+1],dp[i][j]+H[j]); } } cout<<dp[n][0]<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - Code Formula 2015 |
User | haji |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 899 Byte |
Status | AC |
Exec Time | 18 ms |
Memory | 35712 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 100 / 100 | ||
Status |
|
Set Name | Test Cases |
---|---|
All | sample_01.txt, sample_02.txt, test_2_1.txt, test_349_131.txt, test_383_460.txt, test_851_774.txt, test_913_969.txt, test_916_44.txt, test_999_1000.txt, sample_01.txt, sample_02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 18 ms | 35584 KB |
sample_02.txt | AC | 12 ms | 35584 KB |
test_2_1.txt | AC | 12 ms | 35584 KB |
test_349_131.txt | AC | 13 ms | 35584 KB |
test_383_460.txt | AC | 13 ms | 35584 KB |
test_851_774.txt | AC | 16 ms | 35712 KB |
test_913_969.txt | AC | 17 ms | 35712 KB |
test_916_44.txt | AC | 17 ms | 35584 KB |
test_999_1000.txt | AC | 18 ms | 35712 KB |