Submission #682847

# Submission time Handle Problem Language Result Execution time Memory
682847 2023-01-17T06:05:20 Z smartmonky Schools (IZhO13_school) C++14
15 / 100
241 ms 20624 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 = 3e5 + 1;
 

vector <int> a, b;
vector <pair <int,int> > vp;
multiset <int> sta, stb;
int lm, ls, ans, s, m, n;
void solve(){
	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]) || stb.find(vp[i].ss) == stb.end())){
			//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));
				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]) || sta.find(vp[i].ff) == sta.end())){
			//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));
				sta.insert(a[lm]);
			}
			if(stb.find(vp[i].ss) != sta.end())
				stb.erase(stb.find(vp[i].ss));
			lm++;
			s--;
		}
	}
}
main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> s;
    vp.resize(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(rall(a));
	sort(rall(b));
	for(int i = 0; i < m; i++)
		sta.insert(a[i]);
	for(int i = 0; i < s; i++)
		stb.insert(b[i]);
	lm = m, ls = s;
	sort(rall(vp));
	solve();
	for(int i = 0; i < n; i++)swap(vp[i].ff, vp[i].ss);
	solve();
	cout << ans;
}

Compilation message

school.cpp: In function 'void solve()':
school.cpp:22:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   22 |   if(sta.find(vp[i].ff) != sta.end() && (m && !s || m && abs(vp[i].ff - a[lm]) >= abs(vp[i].ss - b[ls]) || stb.find(vp[i].ss) == stb.end())){
      |                                          ~~^~~~~
school.cpp:33:51: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   33 |   }else if(stb.find(vp[i].ss) != stb.end() && (!m && s || s && abs(vp[i].ff - a[lm]) <= abs(vp[i].ss - b[ls]) || sta.find(vp[i].ff) == sta.end())){
      |                                                ~~~^~~~
school.cpp: At global scope:
school.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Incorrect 1 ms 312 KB Output isn't correct
6 Incorrect 1 ms 324 KB Output isn't correct
7 Incorrect 3 ms 596 KB Output isn't correct
8 Incorrect 4 ms 720 KB Output isn't correct
9 Incorrect 3 ms 724 KB Output isn't correct
10 Incorrect 3 ms 724 KB Output isn't correct
11 Incorrect 4 ms 732 KB Output isn't correct
12 Incorrect 5 ms 608 KB Output isn't correct
13 Incorrect 28 ms 3348 KB Output isn't correct
14 Incorrect 47 ms 4920 KB Output isn't correct
15 Correct 70 ms 6860 KB Output is correct
16 Incorrect 241 ms 15376 KB Output isn't correct
17 Incorrect 184 ms 17076 KB Output isn't correct
18 Incorrect 213 ms 16952 KB Output isn't correct
19 Incorrect 190 ms 18488 KB Output isn't correct
20 Incorrect 219 ms 20624 KB Output isn't correct