Submission #61505649


Source Code Expand

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <sstream>
#include <numeric>
#include <cstdio>
#include <bitset>
#include <chrono>
#include <random>
#include <complex>
#include <cmath>
#define F first
#define S second
#define x first
#define y second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define ll long long 
#define div divv
#define real() x
#define imag() y 

using namespace std;

typedef long double ld;
typedef long double DOUBLE;
typedef vector<DOUBLE> VD;
typedef vector<VD> VVD;
typedef vector<int> VI;
typedef complex<double> point;

const int N = 200 * 1000 + 10, K = 64, SQ = 650, mod = 998244353;
const ll inf = 1e18;

ll a[N], b[N], c[N];

void solve()
{
	memset(b, 63, sizeof b); memset(c, 63, sizeof c);
	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 1; i < n; i += 2) b[i / 2] = a[i] - a[i - 1];
	for(int i = 2; i < n; i += 2) c[i / 2 - 1] = a[i] - a[i - 1];
	sort(b, b + n); sort(c, c + n);
	ll ans = a[0] * n;
	for(int i = 1; i < n; i += 2) ans += (n - i) * b[i / 2];
	for(int i = 2; i < n; i += 2) ans += (n - i) * c[i / 2 - 1];
	cout << ans << '\n';
}

int main()
{
	ios::sync_with_stdio(0);
	int t; t = 1; // cin >> t;
	while(t--) solve();
}

Submission Info

Submission Time
Task B - Minimize Sum
User alish
Language C++ 20 (gcc 12.2)
Score 500
Code Size 1483 Byte
Status AC
Exec Time 30 ms
Memory 8320 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 32
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 2 ms 6668 KiB
example_01.txt AC 2 ms 6752 KiB
hand_00.txt AC 2 ms 6752 KiB
hand_01.txt AC 16 ms 8084 KiB
hand_02.txt AC 20 ms 8080 KiB
hand_03.txt AC 20 ms 8096 KiB
hand_04.txt AC 20 ms 8068 KiB
hand_05.txt AC 26 ms 8216 KiB
hand_06.txt AC 25 ms 8084 KiB
hand_07.txt AC 25 ms 8196 KiB
hand_08.txt AC 25 ms 8132 KiB
hand_09.txt AC 19 ms 8208 KiB
random_00.txt AC 15 ms 7280 KiB
random_01.txt AC 2 ms 6560 KiB
random_02.txt AC 26 ms 7896 KiB
random_03.txt AC 2 ms 6756 KiB
random_04.txt AC 29 ms 8064 KiB
random_05.txt AC 30 ms 8320 KiB
random_06.txt AC 2 ms 6556 KiB
random_07.txt AC 30 ms 8228 KiB
random_08.txt AC 4 ms 6456 KiB
random_09.txt AC 16 ms 7444 KiB
random_10.txt AC 29 ms 8064 KiB
random_11.txt AC 30 ms 8140 KiB
random_12.txt AC 15 ms 7256 KiB
random_13.txt AC 20 ms 7688 KiB
random_14.txt AC 2 ms 6648 KiB
random_15.txt AC 2 ms 6560 KiB
random_16.txt AC 27 ms 8012 KiB
random_17.txt AC 2 ms 6456 KiB
random_18.txt AC 27 ms 8068 KiB
random_19.txt AC 27 ms 8128 KiB