제출 #1122445

#제출 시각아이디문제언어결과실행 시간메모리
1122445IcelastBodyguard (JOI21_bodyguard)C++17
6 / 100
4587 ms1269416 KiB
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 6002, INF = 4e18+9;
struct flower{
    ll t, A, B, c;
};
ll cost[maxn][2*maxn][2];
ll f[maxn][maxn];
void sub1(int n, int q, vector<flower> a){
    int N = 6000;
    auto chmax = [&](ll &a, ll b) -> void{
        a = max(a, b);
    };
    for(int i = 1; i <= n; i++){
        ll A = a[i].A*2, B = a[i].B*2;
        if(A == B) continue;
        if(A < B){
            int y = a[i].t*2;
            for(int j = A; j < B; j++){
                chmax(cost[j][y][1], a[i].c);
                y++;
            }
        }else{
            int y = a[i].t*2;
            for(int j = A; j > B; j--){
                chmax(cost[j][y][0], a[i].c);
                y++;
            }
        }
    }
    for(int j = 2*N; j >= 1; j--){
        for(int i = 1; i <= N; i++){
            chmax(f[i][j], f[i-1][j+1]+cost[i][j][0]);
            chmax(f[i][j], f[i][j+1]);
            chmax(f[i][j], f[i+1][j+1]+cost[i][j][1]);
        }
    }
    for(int i = 1; i <= q; i++){
        ll x, y;
        cin >> y >> x;
        if(y > 3000){
            cout << 0 << "\n";
            continue;
        }
        cout << f[x*2][y*2]/2 << "\n";
    }
}
void solve(){
    int n, q;
    cin >> n >> q;
    vector<flower> a(n+1);
    bool issub1 = true;
    for(int i = 1; i <= n; i++){
        cin >> a[i].t >> a[i].A >> a[i].B >> a[i].c;
        if(a[i].t > 3000 || a[i].A > 3000 || a[i].B > 3000){
            issub1 = false;
        }
    }
    if(issub1){
        sub1(n, q, a);
        return;
    }
    sub1(n, q, a);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("MOTOR.inp", "r", stdin);
    //freopen("MOTOR.out", "w", stdout);
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...