이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct T{
ll a, b, i;
};
bool cmp(T a, T b){
return a.a*b.b < b.a*a.b;
}
void solve(){
ll n, w; cin >> n >> w;
vector<T> A(n);
for(int i = 0; i < n; ++i)cin >> A[i].a >> A[i].b, A[i].i = i+1;
sort(A.begin(),A.end(),cmp);
vector<pair<ll,ll>> v(n);
for(int i = 0; i < n; ++i)v[i] = {A[i].a,A[i].b};
ll su = 0;
ll cn = 0;
pair<ll,ll> mn = {0,0};
multiset<ll> cur;
set<pair<ll,ll>> in;
for(int i = 0; i < n; ++i){
su+=v[i].second;
cur.insert(v[i].second);
while(su*v[i].first > w * v[i].second){
su-=*prev(cur.end());
cur.erase(prev(cur.end()));
}
if(cn == cur.size()){
if(mn.first*v[i].second > su*v[i].first*mn.second){
mn = {su*v[i].first,v[i].second};
}
}
if(cn < cur.size()){
cn = cur.size();
mn = {su*v[i].first,v[i].second};
}
}
cout << cn << '\n';
su = 0;
for(int i = 0; i < n; ++i){
su+=v[i].second;
in.insert({v[i].second,i});
while(su*v[i].first > w * v[i].second){
su-=prev(in.end())->first;
in.erase(prev(in.end()));
}
if(in.size() == cn && mn == make_pair(su*v[i].first,v[i].second)){
for(auto x : in)cout << A[x.second].i << '\n';
return;
}
}
}
int main(){
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
hiring.cpp: In function 'void solve()':
hiring.cpp:34:9: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | if(cn == cur.size()){
| ~~~^~~~~~~~~~~~~
hiring.cpp:39:9: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if(cn < cur.size()){
| ~~~^~~~~~~~~~~~
hiring.cpp:53:16: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
53 | if(in.size() == cn && mn == make_pair(su*v[i].first,v[i].second)){
| ~~~~~~~~~~^~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |