1929. Codeforces Round 926 (Div. 2)
寄寄寄。
A. Sasha and the Beautiful Array
容易发现 \(\displaystyle \sum_{i = 2}^{n}(a_i - a_{i - 1}) = a_n - a_1\),令 \(\displaystyle a'_n = \max_{i = 1}^{n}a_i, a'_1 = \min_{i = 1}^{n}a_i\) 即可,其中 \(a'\) 为重排后的数组。
代码:
Code
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/rope>
bool Mbe;
typedef long long i64;
typedef unsigned long long u64;
typedef __int128 i128;
std :: mt19937 rnd (std :: time (0));
template < class T > T gen (const T l, const T r) {return rnd () % (r - l + 1) + l;}
const double pi = std :: acos (-1);
template < class T > inline void read (T &val) {
T x = 0;
bool f = false;
char c = std :: getchar ();
for ( ; c < '0' || c > '9' ; c = std :: getchar ()) f |= (c == '-');
for ( ; c >= '0' && c <= '9' ; c = std :: getchar ()) x = (x << 1) + (x << 3) + (c & 15);
val = (!f) ? (x) : (-x);
return ;
}
#define debug(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
const i64 hashmod1 = 2147483579, hashmod2 = 1610612741, hashmod3 = 805306457;
template < class T, class I > void chkmin (T &p, I q) {T q_ = q; p = std :: min (p, q_); return ;}
template < class T, class I > void chkmax (T &p, I q) {T q_ = q; p = std :: max (p, q_); return ;}
void solve () {
int n, mn = 2e9, mx = -2e9;
read (n);
while (n --) {
int a;
read (a);
chkmax (mx, a);
chkmin (mn, a);
}
printf ("%d\n", mx - mn);
return ;
}
bool Med;
signed main () {
debug ("%.8lf MB\n", (&Mbe - &Med) / 1048576.0);
int _;
read (_);
while (_ --) {
solve ();
}
debug ("%.8lf ms\n", 1e3 * clock () / CLOCKS_PER_SEC);
return 0;
}
// g++ "a.cpp" -o a -std=c++14 -O2 -Wall -Wextra -Wshadow
// check! no inline! (except fastIO)