#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
#define fi first
#define se second
#define endl "\n"
#define pb push_back
#define int long long
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
#define _ << " " <<
const lo inf = 1000000000;
const lo li = 305;
const lo mod = 1000000007;
int n,m,a[li],k,flag,t,b[li],dp[li][li][li];
int cev;
string s;
vector<int> v;
inline int f(int i,int maxi,int mini){
int cevap=0;
if(i>n)return -(a[maxi]-a[mini]);
if(~dp[i][maxi][mini])return dp[i][maxi][mini];
cevap=max(cevap,f(i+1,maxi,mini));
int tmax=maxi;
if(maxi==0 || a[i]>a[maxi])tmax=i;
int tmin=mini;
if(mini==0 || a[i]<a[mini])tmin=i;
cevap=max(cevap,f(i+1,tmax,tmin)+b[i]);
return dp[i][maxi][mini]=cevap;
}
int32_t main(void){
fio();
cin>>n;
memset(dp,-1,sizeof(dp));
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i];
}
cout<<f(1,0,0)<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
107 ms |
222288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
107 ms |
222288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
107 ms |
222288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
107 ms |
222288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |