Submission #165542

# Submission time Handle Problem Language Result Execution time Memory
165542 2019-11-27T12:24:28 Z muhi1112 Cipele (COCI18_cipele) C++17
18 / 90
1000 ms 4324 KB
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define f1 first
#define s2 second
#define pb push_back
#define mp make_pair
#define ll long long
#define fri(a) freopen(a,"r",stdin);
#define fro(a) freopen(a,"w",stdout);
const int N=405;

ll n,m,a,ans,ans1,ans2;
vector<ll>l,r,l1,r1;
int main(){
	//fri("in.txt");
	//fro("out.txt");
	cin>>n>>m;
	for(int i=0;i<n;i++){
		scanf("%lld",&a);
		l.pb(a);
		l1.pb(a);
	}
	for(int i=0;i<m;i++){
		scanf("%lld",&a);
		r.pb(a);
		r1.pb(a);
	}
	sort(l.begin(),l.end());
	sort(r.begin(),r.end());
	sort(l1.begin(),l1.end());
	sort(r1.begin(),r1.end());

	if(n<m){
		for(int i=0;i<n;i++){
			auto j=lower_bound(r.begin(),r.end(),l[i]);
			if(j==r.end())j--;
			if(j>r.begin() && abs(*j-l[i])>abs(*(j-1)-l[i]))j--;
			// for(auto p:r){
			// 	cout<<p<<" ";
			// }
			// cout<<endl;
			// cout<<(*j)<<" "<<l[i]<<endl;
			ans=max(ans,abs(*j-l[i]));
			r.erase(j);
		}
	}
	else if(n>m){
		for(int i=0;i<m;i++){
			auto j=lower_bound(l.begin(),l.end(),r[i]);
			if(j==l.end())j--;
			if(j>l.begin() && abs(*j-r[i])>abs(*(j-1)-r[i]))j--;
			// for(auto p:l){
			// 	cout<<p<<" ";
			// }
			// cout<<endl;
			// cout<<(*j)<<" "<<r[i]<<endl;
			ans=max(ans,abs(*j-r[i]));
			l.erase(j);
		}
	}
	else{
		for(int i=0;i<n;i++){
			auto j=lower_bound(r.begin(),r.end(),l[i]);
			if(j==r.end())j--;
			if(j>r.begin() && abs(*j-l[i])>abs(*(j-1)-l[i]))j--;
			// for(auto p:r){
			// 	cout<<p<<" ";
			// }
			// cout<<endl;
			// cout<<(*j)<<" "<<l[i]<<endl;
			ans1=max(ans1,abs(*j-l[i]));
			r.erase(j);
		}
		for(int i=0;i<m;i++){
			auto j=lower_bound(l1.begin(),l1.end(),r1[i]);
			if(j==l1.end())j--;
			if(j>l1.begin() && abs(*j-r1[i])>abs(*(j-1)-r1[i]))j--;
			// for(auto p:l){
			// 	cout<<p<<" ";
			// }
			// cout<<endl;
			// cout<<(*j)<<" "<<r[i]<<endl;
			ans2=max(ans2,abs(*j-r1[i]));
			l1.erase(j);
		}
		ans=min(ans1,ans2);
	}
	//cout<<"sa"<<endl;
	cout<<ans;
	return 0;
}

Compilation message

cipele.cpp: In function 'int main()':
cipele.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&a);
   ~~~~~^~~~~~~~~~~
cipele.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&a);
   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 4324 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 4320 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 8 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1061 ms 3808 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 4192 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1064 ms 3820 KB Time limit exceeded
2 Halted 0 ms 0 KB -