답안 #682810

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682810 2023-01-17T04:10:53 Z smartmonky 학교 설립 (IZhO13_school) C++14
10 / 100
228 ms 19548 KB
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
 
using namespace std;
 
const int N = 1e5 + 1;

bool comp(pair <int,int> a, pair <int,int> b){
	return max(a.ff,a.ss) > max(b.ff,b.ss);
}

main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, s;
    cin >> n >> m >> s;
    vector <int> a, b;
    vector <pair <int,int> > vp(n);
    for(int i = 0; i < n; i++){
		cin >> vp[i].ff >> vp[i].ss;
		a.pb(vp[i].ff);
		b.pb(vp[i].ss);
	}
	sort(all(vp), comp);
	sort(rall(a));
	sort(rall(b));
	multiset <int> sta, stb;
	for(int i = 0; i < m; i++)
		sta.insert(a[i]);
	for(int i = 0; i < s; i++)
		stb.insert(b[i]);
	int lm = m, ls = s;
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(!s && !m)break;
		if(sta.find(vp[i].ff) != sta.end() && (m && !s || m && abs(vp[i].ff - a[lm]) >= abs(vp[i].ss - b[ls]))){
			//cout <<"1 " << vp[i].ff << endl;
			ans += vp[i].ff;
			if(sta.find(vp[i].ff) != sta.end())
				sta.erase(sta.find(vp[i].ff));
			if(stb.find(vp[i].ss) != stb.end())
				stb.erase(stb.find(vp[i].ss));
			//cout << "what??" << endl;
			stb.insert(b[ls]);
			ls++;
			m--;
		}else if(stb.find(vp[i].ss) != stb.end() && (!m && s || s && abs(vp[i].ff - a[lm]) <= abs(vp[i].ss - b[ls]))){
			//cout <<"2 " << vp[i].ss << endl;
			ans += vp[i].ss;
			if(sta.find(vp[i].ff) != sta.end())
				sta.erase(sta.find(vp[i].ff));
			if(stb.find(vp[i].ss) != sta.end())
				stb.erase(stb.find(vp[i].ss));
			sta.insert(a[lm]);
			lm++;
			s--;
		}
	}
	cout << ans;
}

Compilation message

school.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main(){
      | ^~~~
school.cpp: In function 'int main()':
school.cpp:42:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   42 |   if(sta.find(vp[i].ff) != sta.end() && (m && !s || m && abs(vp[i].ff - a[lm]) >= abs(vp[i].ss - b[ls]))){
      |                                          ~~^~~~~
school.cpp:53:51: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   53 |   }else if(stb.find(vp[i].ss) != stb.end() && (!m && s || s && abs(vp[i].ff - a[lm]) <= abs(vp[i].ss - b[ls]))){
      |                                                ~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Incorrect 3 ms 540 KB Output isn't correct
8 Incorrect 5 ms 596 KB Output isn't correct
9 Incorrect 5 ms 596 KB Output isn't correct
10 Incorrect 4 ms 596 KB Output isn't correct
11 Incorrect 4 ms 596 KB Output isn't correct
12 Incorrect 5 ms 596 KB Output isn't correct
13 Incorrect 36 ms 2964 KB Output isn't correct
14 Incorrect 55 ms 4144 KB Output isn't correct
15 Incorrect 75 ms 6048 KB Output isn't correct
16 Incorrect 220 ms 14256 KB Output isn't correct
17 Incorrect 210 ms 16080 KB Output isn't correct
18 Incorrect 228 ms 15908 KB Output isn't correct
19 Incorrect 212 ms 17440 KB Output isn't correct
20 Incorrect 226 ms 19548 KB Output isn't correct