Submission #107448

# Submission time Handle Problem Language Result Execution time Memory
107448 2019-04-24T13:11:20 Z leonarda Cipele (COCI18_cipele) C++14
90 / 90
52 ms 3196 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pi;
typedef long long int lint;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 10;

int n, m, par;
vector<int> a, b;

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> n >> m;
	if(n >= m) {
		for(int i = 0; i < n; ++i) {
			int x; cin >> x;
			b.pb(x);
		}
		for(int i = 0; i < m; ++i) {
			int x; cin >> x;
			a.pb(x);
		}
			
		sort(a.begin(), a.end());
		sort(b.begin(), b.end());
	} else {
		for(int i = 0; i < n; ++i) {
			int x; cin >> x;
			a.pb(x);
		}
		for(int i = 0; i < m; ++i) {
			int x; cin >> x;
			b.pb(x);
		}
			
		sort(a.begin(), a.end());
		sort(b.begin(), b.end());
	}
	
	if(n == m) {
		int ans = 0;
		for(int i = 0; i < n; ++i)
			ans = max(ans, abs(a[i] - b[i]));
		return cout << ans, 0;
	}

	int hi = 2 * max(abs(a[0] - b[b.size() - 1]), abs(b[0] - a[a.size() - 1])); 
	int lo = 0;
	int mid = lo + (hi - lo) / 2;
	int ans = inf;
	
	while(lo <= hi) {
		mid = lo + (hi - lo) / 2;
		int cur = 0;
		for(int i = 0; i < b.size(); ++i) {
			if(abs(a[cur] - b[i]) <= mid)
				++cur;
			if(cur == a.size()) {
				hi = mid - 1;
				ans = min(ans, mid);
				break;
			}
		}
//		cout << "cur " << cur << " ans " << ans << endl;
		if(!(cur == a.size()))
			lo = mid + 1;
//		cout << hi << " " << lo << endl;
	}
	
	int cur = 0;
	mid = lo + (hi - lo) / 2;
	for(int i = 0; i < b.size(); ++i) {
		if(abs(a[cur] - b[i]) <= mid) 
			++cur;
	}
	if(cur == a.size())
		ans = min(ans, mid);
	
	cout << ans;

return 0;
}

Compilation message

cipele.cpp: In function 'int main()':
cipele.cpp:62:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < b.size(); ++i) {
                  ~~^~~~~~~~~~
cipele.cpp:65:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(cur == a.size()) {
       ~~~~^~~~~~~~~~~
cipele.cpp:72:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(!(cur == a.size()))
        ~~~~^~~~~~~~~~~
cipele.cpp:79:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < b.size(); ++i) {
                 ~~^~~~~~~~~~
cipele.cpp:83:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(cur == a.size())
     ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3068 KB Output is correct
2 Correct 43 ms 3196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 3192 KB Output is correct
2 Correct 45 ms 3188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 2804 KB Output is correct
2 Correct 38 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 3028 KB Output is correct
2 Correct 21 ms 2292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 2812 KB Output is correct
2 Correct 38 ms 2968 KB Output is correct