This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int nx=1e5+5;
int n, tmp;
vector<int> v, x, y;
int solve(int a, int b)
{
x.clear();
y.clear();
vector<int> vs(n);
x.push_back(v[a]);
x.push_back(v[b]);
vs[a]=vs[b]=1;
int g=v[b]-v[a], p=v[b];
for (int i=b+1; i<n; i++) if (v[i]-p==g) x.push_back(v[i]), vs[i]=1;
for (int i=0; i<n;i ++) if (!vs[i]) y.push_back(v[i]);
set<int> s;
for (int i=1; i<y.size(); i++) s.insert(y[i]-y[i-1]);
return (y.empty()||s.size()==1);
}
void show()
{
if (y.empty()) y.push_back(x.back()), x.pop_back();
cout<<x.size()<<'\n';
for (auto t:x) cout<<t<<' ';
cout<<'\n';
cout<<y.size()<<'\n';
for (auto t:y) cout<<t<<' ';
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>tmp, v.push_back(tmp);
sort(v.begin(), v.end());
if (solve(0, 1)) show();
else if (solve(0, 2)) show();
else if (solve(1, 2)) show();
else cout<<-1;
}
Compilation message (stderr)
drvca.cpp: In function 'int solve(int, int)':
drvca.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i=1; i<y.size(); i++) s.insert(y[i]-y[i-1]);
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |