이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix = vector<vector<T>>;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector<int> v(n);
for(int i = 0; i < n; i++)
cin >> v[i];
vector<int> sums;
int minmid = max(0,(n+k)/2-k/2-3), maxmid = min(n-1,(n+k)/2+k/2+3);
for(int i = minmid; i <= maxmid; i++){
for(int j = i+1; j <= maxmid; j++)
sums.push_back(v[i]+v[j]), cout << v[i]+v[j] << '\n';
}
auto findans =[&](int sum){
int p1 = 0, p2 = n-1;
vector<int> resp;
while(p1 < p2){
if(v[p1] + v[p2] > sum){
p2--;
continue;
}
if(v[p1] + v[p2] < sum){
p1++;
continue;
}
resp.push_back(p1+1), resp.push_back(p2+1);
p1++, p2--;
}
sort(all(resp));
// for(int i : resp)
// cout << i << ' ';
// cout << '\n';
};
for(int sum : sums){
int resp = 0;
int p1 = 0, p2 = n-1;
while(p1 < p2){
if(v[p1] + v[p2] > sum){
p2--;
continue;
}
if(v[p1] + v[p2] < sum){
p1++;
continue;
}
p1++, p2--;
resp++;
}
//cout << sum << ' ' << resp << '\n';
if(resp >= n/2){
findans(sum);
return 0;
}
}
}
# | 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... |
# | 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... |