답안 #90783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90783 2018-12-24T11:52:58 Z YottaByte 학교 설립 (IZhO13_school) C++14
25 / 100
136 ms 9256 KB
#include <bits/stdc++.h>

#define pb push_back
#define mk make_pair
#define fr first
#define sc second

using namespace std;

const int N = 3e5 + 5;

int n, x, y, cn1, cn2, used[N];

pair <int, int> a[N];

vector < pair <int, int> > vec1, vec2;

vector <int> ind;

long long ans;

main()
{
	cin >> n >> x >> y;
	
	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d", &a[i].fr, &a[i].sc);
		vec1.pb( {a[i].fr, i} );
		vec2.pb( {a[i].sc, i} );
	}
	sort( vec1.rbegin(), vec1.rend() );
	sort( vec2.rbegin(), vec2.rend() );
	
	for (int i = 0; i < x; i++)
		used[ vec1[i].second ]++, ans += vec1[i].fr;
		
	for (int i = 0; i < y; i++){
		used[ vec2[i].second ]++, ans += vec2[i].fr;
		if ( used[ vec2[i].sc ] == 2 )
			ind.pb( vec2[i].sc );
	}
		
	while ( cn1 < vec1.size() && used[ vec1[cn1].sc ] )
		cn1++;
	
	while ( cn2 < vec2.size() && used[ vec2[cn2].sc ] )
		cn2++;
		
	for (auto to : ind)
	{
		if ( cn2 == vec2.size() || a[to].fr - a[ vec1[cn1].sc ].fr < a[to].sc - a[ vec2[cn2].sc ].sc )
		{
			ans -= a[to].fr;
			ans += a[ vec1[cn1].sc ].fr;
			used[ vec1[cn1].sc ]++;
			used[ to ]--;
			while ( cn1 < vec1.size() && used[ vec1[cn1].sc ] )
				cn1++;
		}
		else
		{
			ans -= a[to].sc;
			ans += a[ vec2[cn2].sc ].sc;
			used[ vec2[cn2].sc ]++;
			used[ to ]--;
			while ( cn2 < vec2.size() && used[ vec2[cn2].sc ] )
				cn2++;
		}
	}
	cout << ans << endl;
}
/**
7 2 3
9 8
10 6 
3 5
1 7
5 7
6 3
5 4
**/

Compilation message

school.cpp:22:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
school.cpp: In function 'int main()':
school.cpp:44:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while ( cn1 < vec1.size() && used[ vec1[cn1].sc ] )
          ~~~~^~~~~~~~~~~~~
school.cpp:47:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while ( cn2 < vec2.size() && used[ vec2[cn2].sc ] )
          ~~~~^~~~~~~~~~~~~
school.cpp:52:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if ( cn2 == vec2.size() || a[to].fr - a[ vec1[cn1].sc ].fr < a[to].sc - a[ vec2[cn2].sc ].sc )
        ~~~~^~~~~~~~~~~~~~
school.cpp:58:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while ( cn1 < vec1.size() && used[ vec1[cn1].sc ] )
            ~~~~^~~~~~~~~~~~~
school.cpp:67:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while ( cn2 < vec2.size() && used[ vec2[cn2].sc ] )
            ~~~~^~~~~~~~~~~~~
school.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a[i].fr, &a[i].sc);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 556 KB Output is correct
4 Incorrect 2 ms 568 KB Output isn't correct
5 Correct 2 ms 568 KB Output is correct
6 Incorrect 2 ms 568 KB Output isn't correct
7 Correct 4 ms 768 KB Output is correct
8 Incorrect 3 ms 808 KB Output isn't correct
9 Incorrect 3 ms 824 KB Output isn't correct
10 Incorrect 4 ms 824 KB Output isn't correct
11 Incorrect 4 ms 824 KB Output isn't correct
12 Incorrect 4 ms 824 KB Output isn't correct
13 Incorrect 16 ms 1756 KB Output isn't correct
14 Incorrect 33 ms 2944 KB Output isn't correct
15 Correct 69 ms 5148 KB Output is correct
16 Incorrect 83 ms 5824 KB Output isn't correct
17 Incorrect 99 ms 6972 KB Output isn't correct
18 Incorrect 106 ms 7480 KB Output isn't correct
19 Incorrect 114 ms 8068 KB Output isn't correct
20 Incorrect 136 ms 9256 KB Output isn't correct