This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define rep(i, n) for(int i = 1; (i) <= (n); ++i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define ford(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define FORD(i, n) for(int i = ((n) - 1); i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "FFILL"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
const int N = 1e3 + 3;
const int LIM = (1 << 16) + 3;
const int INF = 1e9 + 1;
const int LOG = 16;
int n, p, q;
int a[N];
int dp[N][N];
bool check(int w)
{
forn(i, 0, n) forn(j, 0, p) dp[i][j] = INF;
dp[0][0] = 0;
int pos_w = 1, pos_2w = 1;
rep(i, n)
{
while(pos_w <= n && a[pos_w] - a[i] + 1<= w) ++pos_w;
while(pos_2w <= n && a[pos_2w] - a[i] + 1 <= 2 * w) ++pos_2w;
forn(j, 0, p)
{
minimize(dp[pos_w - 1][j + 1], dp[i - 1][j]);
minimize(dp[pos_2w - 1][j], dp[i - 1][j] + 1);
}
}
forn(j, 0, p) if(dp[n][j] <= q) return 1;
return 0;
}
void solve()
{
cin >> n >> p >> q;
rep(i, n) cin >> a[i];
sort(a + 1, a + 1 + n);
p = min(p, n);
q = min(q, n);
int l = 1, r = 1e9, res;
while(l <= r)
{
int mid = l + r >> 1;
if(check(mid)) res = mid, r = mid - 1;
else l = mid + 1;
}
cout << res;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int TC = 1;
if(fopen("note.inp", "r"))
{
freopen("note.inp", "r", stdin);
freopen("note.out", "w", stdout);
}
while(TC--)
{
solve();
}
return 0;
}
Compilation message (stderr)
watching.cpp: In function 'void solve()':
watching.cpp:70:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
70 | int mid = l + r >> 1;
| ~~^~~
watching.cpp: In function 'int main()':
watching.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | freopen("note.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
88 | freopen("note.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |