제출 #367091

#제출 시각아이디문제언어결과실행 시간메모리
367091ritul_kr_singh구경하기 (JOI13_watching)C++17
0 / 100
2 ms512 KiB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"

int n, p, q;
int a[2000];

bool possible(int w){
    vector<array<int, 2>> res = {{a[0], a[0]}};

    for(int i=1; i<n; ++i){
        if(res.back()[0] + w - 1 < a[i]){
            res.push_back({a[i], a[i]});
        }else res.back()[1] = a[i];
    }

    int x = 0, y = 0;

    for(int i=0; i<res.size(); ++i){
        if(i+1 < res.size() and res[i+1][1]-res[i][0]+1<=2*w){
            y += 1;
            i += 1;
        }else x += 1;
    }

    if(y > q){
        x += 2*(y-q);
        y = q;
    }
    if(x > p){
        y += x-p;
        x = p;
    }
    return x<=p and y<=q;
}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n >> p >> q;
    for(int i=0; i<n; ++i) cin >> a[i];
    sort(a, a+n);

    int low = 1, high = 1e9;
    while(low < high){
        int mid = (low+high)/2;
        if(possible(mid)) high = mid;
        else low = mid+1;
    }
    cout << low nl;
}

컴파일 시 표준 에러 (stderr) 메시지

watching.cpp: In function 'bool possible(long long int)':
watching.cpp:22:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i=0; i<res.size(); ++i){
      |                  ~^~~~~~~~~~~
watching.cpp:23:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         if(i+1 < res.size() and res[i+1][1]-res[i][0]+1<=2*w){
      |            ~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...