/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(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 maxc 1000000007
#define maxn 105
#define maxm 2005
#define pii pair <int,int>
#define Task "Go"
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
int n,st,m,dp[maxm][maxn][maxn];
struct house
{
int pos,c,t;
}a[maxn];
void Max(int &x,int y) {if (x < y) x = y;};
int main()
{
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen(Task".inp", "r",stdin);
//freopen(Task".out", "w",stdout);
read(n),read(st),read(m);
FOR(i,1,m)
{
read(a[i].pos);
read(a[i].c);
read(a[i].t);
}
FOR(i,0,2000) FOR(j,1,m) FOR(k,1,m) dp[i][j][k] = -maxc;
FOR(i,1,m)
dp[abs(st - a[i].pos)][i][i] = abs(st - a[i].pos) < a[i].t ? a[i].c : 0;
FOR(i,1,2000) FOR(j,1,m) FOR(k,1,m)
if (j != k)
{
if (j < k)
{
if (i - a[j+1].pos + a[j].pos >= 0)
{
int add = i < a[j].t ? a[j].c : 0;
Max(dp[i][j][k],dp[i - a[j+1].pos + a[j].pos][j+1][k] + add);
}
if (i - a[k].pos + a[j].pos >= 0)
{
int add = i < a[j].t;
Max(dp[i][j][k],dp[i - a[k].pos + a[j].pos][k][j+1] + add);
}
}
else
{
if (i - a[j].pos + a[j-1].pos >= 0)
{
int add = i < a[j].t ? a[j].c : 0;
Max(dp[i][j][k],dp[i - a[j].pos + a[j-1].pos][j-1][k] + add);
}
if (i - a[j].pos + a[k].pos >= 0)
{
int add = i < a[j].t ? a[j].c : 0;
Max(dp[i][j][k],dp[i - a[j].pos + a[k].pos][k][j-1] + add);
}
}
}
int ans = -maxc;
FOR(i,0,2000) ans = max(ans,dp[i][1][m]);
write(ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
11000 KB |
Output is correct |
2 |
Correct |
15 ms |
15996 KB |
Output is correct |
3 |
Correct |
20 ms |
19448 KB |
Output is correct |
4 |
Correct |
31 ms |
24452 KB |
Output is correct |
5 |
Correct |
134 ms |
49260 KB |
Output is correct |
6 |
Correct |
134 ms |
57476 KB |
Output is correct |
7 |
Incorrect |
215 ms |
65940 KB |
Output isn't correct |
8 |
Correct |
312 ms |
74096 KB |
Output is correct |
9 |
Correct |
331 ms |
82328 KB |
Output is correct |
10 |
Incorrect |
454 ms |
86932 KB |
Output isn't correct |