이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
bool vis[505];
int n, k;
int as, bs;
vector<pair<int, int>> a, b;
int todo=0,ptr=0;
long double cans=1e18, ans = 1e18, csum = 0;
vector<int> vec;
int av[1005], bv[1005];
int main() {
cin >> n >> k;
for(int i=0;i<n;i++) {
cin >> as >> bs; av[i] = as; bv[i] = bs;
a.emplace_back(as, i);
b.emplace_back(bs==-1 ? INT_MAX :bs, i);
vec.push_back(i);
}
sort(vec.begin(), vec.end(), [&](int i, int j){
if(bv[i] == -1) return (bool)0;
if(bv[j] == -1) return (bool)1;
if(bv[i]-av[i] == bv[j]-av[j]) return av[i] > av[j];
return bv[j]-av[i] > bv[j]-av[j];
});
//blablbalbllba
for(int k=0;k<vec.size();k++) {
ans = 1e18; csum = 0;
sort(a.begin(), a.end()); sort(b.begin(), b.end());
for(int selb=0;selb<=b.size();selb++) {
vector<bool> vis(n, 0);
todo = k; csum = 0; ptr = 0;
bool broke = 0;
for(int i=0;i<selb;i++) {
if(b[i].first == INT_MAX) broke = 1;
vis[b[i].second] = 1;
csum += 1.00*b[i].first/(i+1); todo--;
}
if(broke) break;
while(ptr<n&&todo > 0){
if(vis[a[ptr].second]){ptr++; continue;}
csum += 1.00*a[ptr].first/(selb+1);
todo--; ptr++;
}
if(todo<=0) ans = min(ans, csum);
}
cans = min(cans, ans);
for(int j=0;j<b.size();j++) if(b[j].second == vec[k]) b[j].first = INT_MAX;
if(bv[vec[k]] == -1) break;
}
cout << cans;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int k=0;k<vec.size();k++) {
| ~^~~~~~~~~~~
Main.cpp:32:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int selb=0;selb<=b.size();selb++) {
| ~~~~^~~~~~~~~~
Main.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int j=0;j<b.size();j++) if(b[j].second == vec[k]) b[j].first = INT_MAX;
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |