Submission #199519

# Submission time Handle Problem Language Result Execution time Memory
199519 2020-02-01T18:04:32 Z ZwariowanyMarcin Cipele (COCI18_cipele) C++14
90 / 90
69 ms 3216 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define LL long long
#define LD long double
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define boost cin.tie(0), ios_base::sync_with_stdio(0);


using namespace std;			
	
const int nax = 1e5 + 111;

int n, m, a;
vector <int> x, y;	

bool ok(int dif) {
	int wsk = 0;
	for (int i = 0; i < ss(x); ++i) {
		while (wsk < ss(y) && abs(x[i] - y[wsk]) > dif) wsk++;
		if (wsk == ss(y)) return false;
		wsk++;
	}
	return true;
}
		

int main() {	
	scanf ("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf ("%d", &a);
		x.pb(a);
	}
	for (int i = 1; i <= m; ++i) {
		scanf ("%d", &a);
		y.pb(a);
	}
	
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	
	if (ss(x) > ss(y)) swap(x, y);
	
	int l = 0;
	int r = 1e9 + 11;
	
	while (l < r) {
		int m = (l + r) / 2;
		if (ok(m)) r = m;
		else l = m + 1;
	}
	printf ("%d\n", l);	
	
	return 0;
}

Compilation message

cipele.cpp: In function 'int main()':
cipele.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d%d", &n, &m);
  ~~~~~~^~~~~~~~~~~~~~~~
cipele.cpp:35:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d", &a);
   ~~~~~~^~~~~~~~~~
cipele.cpp:39:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d", &a);
   ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 47 ms 2928 KB Output is correct
2 Correct 69 ms 3056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 3184 KB Output is correct
2 Correct 67 ms 3216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 376 KB Output is correct
2 Correct 8 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 2800 KB Output is correct
2 Correct 43 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2928 KB Output is correct
2 Correct 35 ms 2288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 2800 KB Output is correct
2 Correct 61 ms 2948 KB Output is correct