/*
UWOZH SQ ATGZVJNZS
XYW LTBMKST XDPCWVYDYD UWATVZYPE VGK (VUNV) MJ S NPYIIST WVA KZIE REJ WVLXXVV QY 1998
OS TGUMVX KZM ECIWL WQ ZPVUBCJRZU UPYMR KCNC EJ KWQOARJM, RVQVK, XSJXFYZLKLP, NQOZSJ,
GZ XPWZU WGZV KZM TIXVJVPO.
MW QWF OVZWL EJ GFHG ECMJ, QWF HEP TM TNWLWL YJXZXQNVXZGV FIHVJ BSZ
TIGDTNMFFA ZA WVUBTJR 512© FX BSZ HZYQEVP DATWZREACX XSGQZTBLK SKE (YQTS)
BZ ZJWWKE MIDGDLG SW LPP VFFNM-CZTFJBPY MEXZTIKVEMYOW.
*/
#include <algorithm>
#include <utility>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <climits>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <random>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>
#include <limits>
using namespace std;
#pragma GCC optimize("O3")
#define TASK ""
#define lnBr cout << '\n'
namespace sub1
{
int n,p,q;
const int maxn = 100;
bool f[maxn+1][maxn+1][maxn+1];
int a[maxn+1];
bool check(int w)
{
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= p; j++)
{
for (int k = 0; k <= q; k++) {f[i][j][k] = true;}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 0; j <= p; j++)
{
for (int k = 0; k <= q; k++)
{
f[i][j][k] = false;
if (j > 0)
{
int mini = max(1, a[i] - w+1);
auto it = lower_bound(a+1, a+n+1, mini); int idx = it - a; idx--;
f[i][j][k] = f[idx][j-1][k];
}
if (k > 0)
{
int mini = max(1, a[i] - 2*w+1);
auto it = lower_bound(a+1, a+n+1, mini); int idx = it - a; idx--;
f[i][j][k] = f[i][j][k] || f[idx][j][k-1];
}
//cerr << i << " " << j << " " << k << " " << f[i][j][k] << '\n';
}
}
}
return f[n][p][q];
}
void Solve(int xx)
{
n = xx; cin >> p >> q; p = min(p, n); q = min(q, n);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
sort(a+1, a+n+1);
//cout << check(1) << '\n';
int low = 1, high = 1e9;
while(low <= high)
{
int w = (low+high)/2;
if (!check(w)) {low = w+1;} else {high = w-1;}
}
cout << low;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int n; cin >> n;
if (n <= 100)
{
sub1::Solve(n);
}
}
Compilation message
watching.cpp: In function 'int main()':
watching.cpp:112:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
112 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
716 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
43 ms |
1316 KB |
Output is correct |
5 |
Correct |
38 ms |
716 KB |
Output is correct |
6 |
Correct |
482 ms |
1304 KB |
Output is correct |
7 |
Correct |
2 ms |
716 KB |
Output is correct |
8 |
Correct |
5 ms |
716 KB |
Output is correct |
9 |
Correct |
5 ms |
848 KB |
Output is correct |
10 |
Correct |
47 ms |
852 KB |
Output is correct |
11 |
Correct |
54 ms |
1228 KB |
Output is correct |
12 |
Correct |
126 ms |
1100 KB |
Output is correct |
13 |
Correct |
2 ms |
716 KB |
Output is correct |
14 |
Correct |
3 ms |
716 KB |
Output is correct |
15 |
Correct |
4 ms |
772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |