답안 #640758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640758 2022-09-15T07:45:34 Z peter940324 Let's Win the Election (JOI22_ho_t3) C++17
10 / 100
32 ms 404 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pii pair<double,double>
#define ff first
#define ss second
#define mp make_pair

#define pb push_back
#define pf push_front
#define all(x) x.begin(),x.end()

#define de(x) cout << #x << ' ' << x << '\n';
template<class T> void prt(T l,T r){
  while(l!=r) cout << *l << ' ',l++;
  cout << '\n';
}

const int N=1e6+5,M=1e9+7,INF=1e18;

signed main(){
  IO
	int n,k;cin >> n >> k;
	vector<double> a(n),b(n);
	for(int i=0;i<n;i++) cin >> a[i] >> b[i];
	int cnt=n;
	for(int i=0;i<n;i++) if(b[i]==-1) b[i]=INF,cnt--;
	double ans=0;
	set<int> A,B;
	vector<pii> v(n);
	for(int i=0;i<n;i++){
		v[i]=mp(a[i],i);
	}
	sort(all(v));
	for(int i=0;i<k;i++){
		A.insert(v[i].ss);
		ans+=v[i].ff;
	}
	for(double c=1;c<=min(cnt,k);c++){
		int mxa=0,mxai=-1;
		for(auto x:A){
			if(a[x]>mxa){
				mxa=a[x];
				mxai=x;
			}
		}
		int mn=INF,mni=-1;
		for(int i=0;i<n;i++){
			if(B.count(i)) continue;
			if(A.count(i)){
				if(b[i]-a[i]<mn){
					mn=b[i]-a[i];
					mni=i;
				}
			}else{
				if(b[i]-mxa<mn){
					mn=b[i]-mxa;
					mni=i;
				}
			}
		}
		if(A.count(mni)){
			A.erase(mni);
			B.insert(mni);
		}else{
			A.erase(mxai);
			B.insert(mni);
		}
		double sum=0,cc=1;
		vector<double> bb,aa;
		for(auto x:B){
			bb.pb(b[x]);
		}
		for(auto x:A){
			aa.pb(a[x]);
		}
		sort(all(bb));
		sort(all(aa));
		for(int i=0;i<bb.size();i++){
			sum+=bb[i]/cc;
			cc++;
		}
		for(int i=0;i<aa.size();i++){
			sum+=aa[i]/cc;
		}
		ans=min(ans,sum);
	}
	cout << setprecision(15) << fixed;
	cout << ans << '\n';
  return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:83:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |   for(int i=0;i<bb.size();i++){
      |               ~^~~~~~~~~~
Main.cpp:87:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |   for(int i=0;i<aa.size();i++){
      |               ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 4 ms 340 KB Output is correct
13 Correct 5 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 16 ms 400 KB Output is correct
16 Correct 15 ms 400 KB Output is correct
17 Correct 5 ms 340 KB Output is correct
18 Correct 31 ms 340 KB Output is correct
19 Correct 20 ms 404 KB Output is correct
20 Correct 7 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Incorrect 0 ms 212 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 4 ms 340 KB Output is correct
13 Correct 5 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 16 ms 400 KB Output is correct
16 Correct 15 ms 400 KB Output is correct
17 Correct 5 ms 340 KB Output is correct
18 Correct 31 ms 340 KB Output is correct
19 Correct 20 ms 404 KB Output is correct
20 Correct 7 ms 340 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 320 KB Output is correct
31 Incorrect 0 ms 212 KB Output isn't correct
32 Halted 0 ms 0 KB -