# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
368017 |
2021-02-19T10:16:41 Z |
b23v |
Watching (JOI13_watching) |
C++14 |
|
543 ms |
12452 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <cstring>
#include <deque>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using ii = pair<int,int>;
using vii = vector<pair<int,int>>;
using vb = vector<bool>;
template<typename T>
using Graph = vector<vector<T>>;
int n, p, q;
vector<ll> A;
bool check(ll w)
{
Graph<int> dp(p + 1, vi(n + 1, 1e5));
for(int i = 0; i <= p; ++i)
{
dp[0][0] = 0;
int l = 1, r = 1;
for(int j = 1; j <= n; ++j)
{
while(l <= n && A[l] < A[j] - w + 1) ++l;
while(r <= n && A[r] < A[j] - 2 * w + 1) ++r;
dp[i][j] = min(dp[i][j], dp[i][r - 1] + 1);
if(i) dp[i][j] = min(dp[i][j], dp[i - 1][l - 1]);
}
}
return dp[p][n] <= q;
}
void solve()
{
cin >> n >> p >> q;
p = min(n, p);
A.assign(n + 1, 0);
for(int i = 1; i <= n; ++i) cin >> A[i];
sort(A.begin(), A.end());
ll ans = -1;
ll L = 1, R = ll(1e9);
while(L <= R)
{
ll mid = L + (R - L) / 2;
if(check(mid))
{
ans = mid;
R = mid - 1;
} else
{
L = mid + 1;
}
}
cout << ans << '\n';
}
int main ()
{
#ifdef LOCAL
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int tc = 1;
// cin >> tc;
while(tc--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
543 ms |
12452 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |