Submission #269808

# Submission time Handle Problem Language Result Execution time Memory
269808 2020-08-17T10:31:31 Z kaplanbar Go (COCI18_go) C++14
20 / 100
2 ms 1188 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Pk {
    int a, b, t;
    bool operator<(const Pk other) const {
        return a < other.a;
    }
};
int n, k, m, sz1, sz2, dp[105][2005];
Pk v1[105],v2[105];
int f(int idx, int T) {
    if(idx>=sz1) return 0;
    if(~dp[idx][T]) return dp[idx][T];
    ll ret=0;
    if(T<v1[idx].t) ret+=v1[idx].b;
    if(idx!=sz1-1) {
        ret+=f(idx+1,T+v1[idx+1].a-v1[idx].a);
    }
    return dp[idx][T]=ret;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    memset(dp,-1,sizeof dp);
    cin >> n >> k >> m;
    ll ans=0;
    for(int i = 0; i < m; i++) {
        int a, b, t;
        cin >> a >> b >> t;
        if(a==k) {
            ans += b;
            continue;
        }
        if(a>k) v1[sz1++]={a,b,t};
        else v2[sz2++]={a,b,t};
    }
    sort(v1, v1+sz1);
    
    sort(v2, v2+sz2);
    reverse(v2, v2+sz2);

    ans = sz1 ? f(0,v1[0].a-k) : 0;

    ll sum = 0;

    for(int i = 0; i < sz2; i++) {
        if(v2[i].t > k - v2[i].a) {
            sum += v2[i].b;
        }
        ans = max(ans, sum + sz1 ? f(0, k - v2[i].a + v1[0].a - v2[i].a) : 0ll);
    }

    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1152 KB Output isn't correct
2 Incorrect 1 ms 1152 KB Output isn't correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Incorrect 1 ms 1152 KB Output isn't correct
6 Incorrect 1 ms 1152 KB Output isn't correct
7 Incorrect 1 ms 1188 KB Output isn't correct
8 Incorrect 2 ms 1152 KB Output isn't correct
9 Incorrect 1 ms 1152 KB Output isn't correct
10 Incorrect 1 ms 1152 KB Output isn't correct