답안 #1001827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001827 2024-06-19T07:56:36 Z HasanV11010238 구경하기 (JOI13_watching) C++17
0 / 100
14 ms 644 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1000000000
int n, p, q;
vector<int> a;
int main(){
    cin>>n>>p>>q;
    a.resize(n + 1);
    for (int i = 1; i <= n; i++){
        cin>>a[i];
    }
    set<vector<int>> s;
    for (int i = 1; i <= n; i++){
        s.insert({a[i], a[i]});
    }
    vector<int> fi, se;
    while (s.size() > p + q){
        fi = {0, 0}, se = {1000000000, 1000000000};
        auto it = s.begin();
        while(it != s.end()){
            auto ne = next(it);
            if (ne != s.end()){
                if (ne->at(0) - it->at(1) < se[0] - fi[1]){
                    fi = *it;
                    se = *ne;
                }
            }
            it = ne;
        }
        vector<int> fu = {fi[0], se[1]};
        s.erase(fi);
        s.erase(se);
        s.insert(fu);
    }
    vector<int> fin;
    for (auto el : s){
        fin.push_back(el[1] - el[0] + 1);
    }
    sort(fin.begin(), fin.end());
    reverse(fin.begin(), fin.end());
    int ans = 0;
    for (int i = 0; i < p + q; i++){
        if (i < q){
            ans = max(ans, int(ceil(double(fin[i]) / (double)2)));
        }
        else{
            ans = max(ans, fin[i]);
        }
    }
    cout<<ans;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:18:21: warning: comparison of integer expressions of different signedness: 'std::set<std::vector<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   18 |     while (s.size() > p + q){
      |            ~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 644 KB Output isn't correct
2 Halted 0 ms 0 KB -