Submission #672180

# Submission time Handle Problem Language Result Execution time Memory
672180 2022-12-14T23:10:44 Z Charizard2021 Cipele (COCI18_cipele) C++17
18 / 90
88 ms 3748 KB
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, m;
    cin >> n >> m;
    vector<long long> l(n);
    vector<long long> r(m);
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    for(int i = 0; i < m; i++){
        cin >> r[i];
    }
    sort(l.begin(), l.end());
    sort(r.begin(), r.end());
    if(n > m){
        swap(l, r);
        swap(n, m);
    }
    bool visited[m];
    long long ans = 0;
    memset(visited, false, sizeof(visited));
    for(long long i = 0;i < n; i++){
        long long lo = 0;
        long long hi = m - 1;
        lo--;
    	while (lo < hi) {
    		long long mid = lo + (hi - lo + 1) / 2;
    		if (r[mid] <= l[i] && !visited[mid]) {
    			lo = mid;
    		} else {
    			hi = mid - 1;
    		}
    	}
    	long long cur_dif = INT_MAX;
    	long long cur = -1;
    	if(lo != -1){
    	    cur_dif = l[i] - r[lo];
    	    cur = lo;
    	}
    	long long lo2 = 0;
        long long hi2 = m - 1;
        hi2++;
    	while (lo2 < hi2) {
    		long long mid = lo2 + (hi2 - lo2) / 2;
    		if (r[mid] >= l[i] && !visited[mid]) {
    			hi2 = mid;
    		} else {
    			lo2 = mid + 1;
    		}
    	}
    	if(lo2 != m){
    	    if(cur_dif > abs(l[i] - r[lo2])){
    	        cur_dif = abs(l[i] - r[lo2]);
    	        cur = lo2;
    	    }
    	}
    	if(cur != -1){
    	    visited[cur] = true;
    	    ans = max(ans, cur_dif);
    	}
    }
    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 70 ms 3388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 3748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 312 KB Output is correct
2 Correct 5 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 5 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 3024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 3272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 3036 KB Output isn't correct
2 Halted 0 ms 0 KB -