#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define watch(x) cout<<(#x)<<"="<<(x)<<endl
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265358979323846264338327
#define INF 0x3f3f3f3f
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define MAXN 1005
int n,q;
ll h[MAXN],a[MAXN],b[MAXN];
ll dp[MAXN][MAXN];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
mset(dp,-1);
cin>>n;
forn(i,0,n){
cin>>h[i]>>a[i]>>b[i];
}
forn(d,1,n){
forn(i,0,n-d){
int j=i+d;
dp[i][j]=max(dp[i+1][j],dp[i][j-1]);
if(a[i]<=d && d<=b[i] && a[j]<=d && d<=b[j]){
dp[i][j]=max(dp[i][j],abs(h[i]-h[j]));
}
}
}
cin>>q;
forn(it,0,q){
int s,e; cin>>s>>e; s--; e--;
cout<<dp[s][e]<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8320 KB |
Output is correct |
2 |
Correct |
10 ms |
8320 KB |
Output is correct |
3 |
Correct |
10 ms |
8320 KB |
Output is correct |
4 |
Correct |
11 ms |
8320 KB |
Output is correct |
5 |
Correct |
9 ms |
8320 KB |
Output is correct |
6 |
Correct |
9 ms |
8192 KB |
Output is correct |
7 |
Correct |
9 ms |
8320 KB |
Output is correct |
8 |
Correct |
10 ms |
8320 KB |
Output is correct |
9 |
Correct |
10 ms |
8320 KB |
Output is correct |
10 |
Correct |
9 ms |
8320 KB |
Output is correct |
11 |
Correct |
8 ms |
8192 KB |
Output is correct |
12 |
Correct |
10 ms |
8320 KB |
Output is correct |
13 |
Correct |
9 ms |
8192 KB |
Output is correct |
14 |
Correct |
11 ms |
8320 KB |
Output is correct |
15 |
Correct |
9 ms |
8192 KB |
Output is correct |
16 |
Correct |
9 ms |
8192 KB |
Output is correct |
17 |
Correct |
9 ms |
8188 KB |
Output is correct |
18 |
Correct |
8 ms |
8192 KB |
Output is correct |
19 |
Correct |
8 ms |
8320 KB |
Output is correct |
20 |
Correct |
9 ms |
8192 KB |
Output is correct |
21 |
Correct |
10 ms |
8320 KB |
Output is correct |
22 |
Correct |
9 ms |
8192 KB |
Output is correct |
23 |
Correct |
9 ms |
8192 KB |
Output is correct |
24 |
Correct |
9 ms |
8320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8320 KB |
Output is correct |
2 |
Correct |
10 ms |
8320 KB |
Output is correct |
3 |
Correct |
10 ms |
8320 KB |
Output is correct |
4 |
Correct |
11 ms |
8320 KB |
Output is correct |
5 |
Correct |
9 ms |
8320 KB |
Output is correct |
6 |
Correct |
9 ms |
8192 KB |
Output is correct |
7 |
Correct |
9 ms |
8320 KB |
Output is correct |
8 |
Correct |
10 ms |
8320 KB |
Output is correct |
9 |
Correct |
10 ms |
8320 KB |
Output is correct |
10 |
Correct |
9 ms |
8320 KB |
Output is correct |
11 |
Correct |
8 ms |
8192 KB |
Output is correct |
12 |
Correct |
10 ms |
8320 KB |
Output is correct |
13 |
Correct |
9 ms |
8192 KB |
Output is correct |
14 |
Correct |
11 ms |
8320 KB |
Output is correct |
15 |
Correct |
9 ms |
8192 KB |
Output is correct |
16 |
Correct |
9 ms |
8192 KB |
Output is correct |
17 |
Correct |
9 ms |
8188 KB |
Output is correct |
18 |
Correct |
8 ms |
8192 KB |
Output is correct |
19 |
Correct |
8 ms |
8320 KB |
Output is correct |
20 |
Correct |
9 ms |
8192 KB |
Output is correct |
21 |
Correct |
10 ms |
8320 KB |
Output is correct |
22 |
Correct |
9 ms |
8192 KB |
Output is correct |
23 |
Correct |
9 ms |
8192 KB |
Output is correct |
24 |
Correct |
9 ms |
8320 KB |
Output is correct |
25 |
Correct |
56 ms |
9976 KB |
Output is correct |
26 |
Runtime error |
18 ms |
16640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
21 ms |
16356 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8320 KB |
Output is correct |
2 |
Correct |
10 ms |
8320 KB |
Output is correct |
3 |
Correct |
10 ms |
8320 KB |
Output is correct |
4 |
Correct |
11 ms |
8320 KB |
Output is correct |
5 |
Correct |
9 ms |
8320 KB |
Output is correct |
6 |
Correct |
9 ms |
8192 KB |
Output is correct |
7 |
Correct |
9 ms |
8320 KB |
Output is correct |
8 |
Correct |
10 ms |
8320 KB |
Output is correct |
9 |
Correct |
10 ms |
8320 KB |
Output is correct |
10 |
Correct |
9 ms |
8320 KB |
Output is correct |
11 |
Correct |
8 ms |
8192 KB |
Output is correct |
12 |
Correct |
10 ms |
8320 KB |
Output is correct |
13 |
Correct |
9 ms |
8192 KB |
Output is correct |
14 |
Correct |
11 ms |
8320 KB |
Output is correct |
15 |
Correct |
9 ms |
8192 KB |
Output is correct |
16 |
Correct |
9 ms |
8192 KB |
Output is correct |
17 |
Correct |
9 ms |
8188 KB |
Output is correct |
18 |
Correct |
8 ms |
8192 KB |
Output is correct |
19 |
Correct |
8 ms |
8320 KB |
Output is correct |
20 |
Correct |
9 ms |
8192 KB |
Output is correct |
21 |
Correct |
10 ms |
8320 KB |
Output is correct |
22 |
Correct |
9 ms |
8192 KB |
Output is correct |
23 |
Correct |
9 ms |
8192 KB |
Output is correct |
24 |
Correct |
9 ms |
8320 KB |
Output is correct |
25 |
Correct |
56 ms |
9976 KB |
Output is correct |
26 |
Runtime error |
18 ms |
16640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
27 |
Halted |
0 ms |
0 KB |
- |