# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
915292 | jpfr12 | Akcija (COCI15_akcija) | C++14 | 15 ms | 1116 KiB |
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 <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <string>
#include <map>
#include <math.h>
#include <cmath>
#include <climits>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
#include <fstream>
#include <bitset>
#include <iomanip>
typedef long long ll;
using namespace std;
int MOD = (int)1e9;
int MAXN = 1e6;
//classes
//global
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
//ifstream fin("input.txt");
//ofstream fout("output.txt");
//stop
int n;
cin >> n;
vector<ll> vec(n);
for(ll& i: vec) cin >> i;
if(n == 1){
cout << vec[0] << '\n';
return 0;
}
sort(vec.begin(), vec.end());
int left = 0, right = n-1;
ll sum = 0;
while(left+1 < right){
sum += vec[right] + vec[left+1];
right--;
left += 2;
}
if(left+1 == right) sum += vec[right] + vec[left];
else if(left == right) sum += vec[right];
cout << sum << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |