Submission #711380

#TimeUsernameProblemLanguageResultExecution timeMemory
711380aVeCipele (COCI18_cipele)C++14
90 / 90
42 ms1164 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define vi vector<int> #define vl vector<ll> #define mp make_pair #define pb push_back #define se second #define fi first using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif clock_t startTime; double getCurrentTime() { return (double)(clock() - startTime) / CLOCKS_PER_SEC; } ll set_on(ll n, ll k){ return (n |= 1 << k); } ll set_off(ll n, ll k){ return (n &= ~(1UL << k)); } bool check_bit(ll n, ll k){ int bit = (n >> k) & 1U; if(bit == 1) return true; return false; } void solve(){ int n, m; cin>>n>>m; vi levo(n),desno(m); for(int i = 0; i < n; i++) cin>>levo[i]; for(int i = 0; i < m; i++) cin>>desno[i]; sort(levo.begin(), levo.end()); sort(desno.begin(), desno.end()); ll l = 0, r = 1e9-1, ans = -1; while(l <= r){ ll mid = l + (r - l) / 2; // mid is maximum diff possible bool can = true; int li = 0; for(int i = 0; i < min(n, m); i++){ if(n < m){ if(li >= m){ can = false; break; } if(abs(levo[i] - desno[li]) <= mid){ li++; continue; } else{ while(li < m && abs(levo[i] - desno[li]) > mid){ li++; } if(li >= m){ can = false; break; } li++; continue; } } else{ if(li >= n){ can = false; break; } if(abs(levo[li] - desno[i]) <= mid){ li++; continue; } else{ while(li < n && abs(levo[li] - desno[i]) > mid) li++; if(li >= n){ can = false; break; } li++; continue; } } } // debug(l, mid, r, can); if(can){ ans = mid; r = mid - 1; } else l = mid + 1; } cout<<ans<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout<<fixed; startTime = clock(); int t=1; // cin>>t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...