Submission #1299436

#TimeUsernameProblemLanguageResultExecution timeMemory
1299436sitingfakeWatching (JOI13_watching)C++20
100 / 100
110 ms16116 KiB
#include<bits/stdc++.h>
using namespace std;

// define

#define execute cerr << " Time: " << fixed << setprecision(6) << (1.0 * clock() / CLOCKS_PER_SEC) << "s\n";
#define ll long long
#define ii pair <int , int>
#define iii pair <int , ii>
#define se second
#define fi first
#define all(v) (v).begin() , (v).end()
#define Unique(v) sort(all(v)) , v.resize(unique(all(v)) - v.begin())
#define bit(x,i) (((x) >> (i)) & 1LL)
#define flip(x,i) ((x) ^ (1LL << (i)))
#define ms(d,x) memset(d , x , sizeof(d))
#define exist __exist
#define ends __ends
#define visit visited
#define left __left
#define right __right
#define prev __prev
#define next __next
#define sitingfake 1
#define orz 1
//constant

const long long mod = 1e9 + 7;
const long long linf = 4557430888798830399LL;
const long long nlinf = -4485090715960753727LL;
const int LOG = 20;
const int inf = 1061109567;
const int ninf = -1044266559;
const int dx[] = {0 , -1 , 0 , 1};
const int dy[] = {-1 , 0 , 1 , 0};

template<typename T> bool maximize(T &a, const T &b)
{
    if(a < b) {a = b; return 1;}
    return 0;
}

template<typename T> bool minimize(T &a, const T &b)
{
    if(a > b) {a = b; return 1;}
    return 0;
}

void Plus(ll & a ,ll b)
{
    b %= mod;
    a += b;
    if(a < 0) a += mod;
    a %= mod;
    return;
}

void Mul(ll & a, ll b)
{
    (a *= (b % mod)) %= mod;
    return;
}

//code
const int maxn = 2002;

int a[maxn];
int dp[maxn][maxn];

int n , P , Q;

bool valid(int w)
{
    dp[0][0] = 0;
    int itW = 1 , it2W = 1;

    for(int i = 1; i <= n; i++)
    {
        while(a[i] - a[itW] + 1 > w) itW++;
        while(a[i] - a[it2W] + 1 > 2 * w) it2W++;

        for(int j = 0; j <= P; j++)
        {
            dp[i][j] = inf;
            if(j) dp[i][j] = min(dp[i][j] , dp[itW - 1][j - 1]);
            dp[i][j] = min(dp[i][j] , dp[it2W - 1][j] + 1);
        }
    }
    for(int i = P; i >= 0; i--) if(dp[n][i] <= Q) return 1;
    return 0;
}
void solve(void)
{
    cin >> n >> P >> Q;
    if(P + Q >= n)
    {
        cout << "1";
        return;
    }
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    sort(a + 1 , a + n + 1);
    int left = 1 , right = 1e9 , ans = -1;

    while(left <= right){
        int mid = (left + right) >> 1;
        if(valid(mid)){
            ans = mid;
            right = mid - 1;
        }
        else left = mid + 1;
    }
    cout << ans;
}
/**
**/
signed main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   #define task ""

   if(fopen(task".inp","r"))
   {
       freopen(task".inp","r",stdin);
       freopen(task".out","w",stdout);
   }

   int tc = 1;
//   cin >> tc;
   while(tc--) solve();

//   execute;
}



Compilation message (stderr)

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