Submission #1261474

#TimeUsernameProblemLanguageResultExecution timeMemory
1261474hoa208Watching (JOI13_watching)C++20
100 / 100
272 ms31892 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
#define t_test int t;cin >> t;while(t--)
const   ll mod = 1e9 + 7;
const   ll INF = 1e18;
inline  void adm(ll &x){if(x>=mod)x%=mod;else if(x<0)x+=mod;}
//--------------------------------------------------------------------

ll n, p, q;
const ll N = 2003;
ll a[N];
ll pos_p[N], pos_q[N], dp[N][N];
bool check(ll w) {
    FOR(i, 1, n) {
        ll sum = 1;
        FORD(j, i, 1) {
            if(sum <= w) {
                pos_p[i] = j;
            }
            if(sum <= 2 * w) {
                pos_q[i] = j;
            }
            sum += a[j] - a[j - 1];
        }
    }
    memset(dp, -1, sizeof dp);
    dp[0][0] = q;
    FOR(i, 1, n) {
        FOR(j, 0, p) {
            ll u = pos_p[i], v = pos_q[i];
            if(j - 1 >= 0) dp[i][j] = dp[u - 1][j - 1];
            dp[i][j] = max(dp[i][j], dp[v - 1][j] - 1);
        }
    }
    FOR(i, 0, p) {
        if(dp[n][i] >= 0) return true;
    }
    return false;
}
void hbmt() {
    cin >> n >> p >> q;
    p = min(n, p);
    FOR(i, 1, n) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    ll l = 1, r = a[n], w = -1;
    while(l <= r) {
        ll mid = l + r >> 1;
        if(check(mid)) {
            r = mid - 1;
            w = mid;
        }
        else l = mid + 1;
    }
    cout << w;

}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    
    if(fopen("hbmt.inp", "r")) {
        freopen("hbmt.inp", "r", stdin);
        freopen("hbmt.out", "w", stdout);
    }
    
    // t_test 
    hbmt();
    return 0;
}

Compilation message (stderr)

watching.cpp: In function 'int main()':
watching.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen("hbmt.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen("hbmt.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...