#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#define int long long
using namespace std;
int N,Q;
int T[2900],A[2900],B[2900],C[2900];
int P[2900],X[2900];
int dp[6400][6400];
int verc[6400][6400];
int horc[6400][6400];
vector<int>pl;
vector<int>ml;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N>>Q;
int i;
for(i=0;i<N;i++)
{
cin >> T[i]>>A[i]>>B[i]>>C[i];
if(A[i]>B[i])
{
ml.push_back(T[i]-A[i]);
pl.push_back(T[i]+A[i]);
ml.push_back(T[i]+A[i]-2*B[i]);
}
else
{
ml.push_back(T[i]-A[i]);
pl.push_back(T[i]+A[i]);
pl.push_back(T[i]+B[i]*2-A[i]);
}
}
for(i=0;i<Q;i++)
{
cin >>P[i]>>X[i];
ml.push_back(P[i]-X[i]);
pl.push_back(P[i]+X[i]);
}
sort(ml.begin(),ml.end());
sort(pl.begin(),pl.end());
ml.erase(unique(ml.begin(),ml.end()),ml.end());
pl.erase(unique(pl.begin(),pl.end()),pl.end());
for(i=0;i<N;i++)
{
if(A[i]>B[i])
{
int s=lower_bound(ml.begin(),ml.end(),T[i]-A[i])-ml.begin();
int c=lower_bound(pl.begin(),pl.end(),T[i]+A[i])-pl.begin();
int e=lower_bound(ml.begin(),ml.end(),T[i]+A[i]-2*B[i])-ml.begin();
int j;
for(j=s;j<e;j++)
{
verc[j+1][c]+=C[i]*(ml[j+1]-ml[j])/2;
}
}
else
{
int c=lower_bound(ml.begin(),ml.end(),T[i]-A[i])-ml.begin();
int s=lower_bound(pl.begin(),pl.end(),T[i]+A[i])-pl.begin();
int e=lower_bound(pl.begin(),pl.end(),T[i]-A[i]+2*B[i])-pl.begin();
int j;
for(j=s;j<e;j++)
{
horc[c][j+1]+=C[i]*(pl[j+1]-pl[j])/2;
}
}
}
for(i=0;i<Q;i++)
{
memset(dp,-60,sizeof(dp));
int s=lower_bound(ml.begin(),ml.end(),P[i]-X[i])-ml.begin();
int e=lower_bound(pl.begin(),pl.end(),P[i]+X[i])-pl.begin();
dp[s][e]=0;
for(int i=0;i<ml.size();i++)
{
int j;
for(j=0;j<pl.size();j++)
{
if(i)
{
dp[i][j]=max(dp[i][j],dp[i-1][j]+verc[i][j]);
}
if(j)
{
dp[i][j]=max(dp[i][j],dp[i][j-1]+horc[i][j]);
}
}
}
cout <<dp[ml.size()-1][pl.size()-1]<<'\n';
}
}
Compilation message
bodyguard.cpp: In function 'int main()':
bodyguard.cpp:79:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i=0;i<ml.size();i++)
| ~^~~~~~~~~~
bodyguard.cpp:82:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(j=0;j<pl.size();j++)
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
25110 ms |
509860 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
418 ms |
470372 KB |
Output is correct |
2 |
Correct |
408 ms |
469588 KB |
Output is correct |
3 |
Correct |
424 ms |
467104 KB |
Output is correct |
4 |
Correct |
189 ms |
344148 KB |
Output is correct |
5 |
Correct |
421 ms |
403316 KB |
Output is correct |
6 |
Correct |
360 ms |
376728 KB |
Output is correct |
7 |
Correct |
449 ms |
402964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
418 ms |
470372 KB |
Output is correct |
2 |
Correct |
408 ms |
469588 KB |
Output is correct |
3 |
Correct |
424 ms |
467104 KB |
Output is correct |
4 |
Correct |
189 ms |
344148 KB |
Output is correct |
5 |
Correct |
421 ms |
403316 KB |
Output is correct |
6 |
Correct |
360 ms |
376728 KB |
Output is correct |
7 |
Correct |
449 ms |
402964 KB |
Output is correct |
8 |
Runtime error |
970 ms |
871448 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
418 ms |
470372 KB |
Output is correct |
2 |
Correct |
408 ms |
469588 KB |
Output is correct |
3 |
Correct |
424 ms |
467104 KB |
Output is correct |
4 |
Correct |
189 ms |
344148 KB |
Output is correct |
5 |
Correct |
421 ms |
403316 KB |
Output is correct |
6 |
Correct |
360 ms |
376728 KB |
Output is correct |
7 |
Correct |
449 ms |
402964 KB |
Output is correct |
8 |
Runtime error |
970 ms |
871448 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
25110 ms |
509860 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |