A题
最值序列
https://ac.nowcoder.com/acm/contest/5961/A
思路:
毫无疑问,先把小的数加起来再依次乘最优,证明:
Code:
#include <iostream> #include <cstdio> #include <algorithm> #define ll long long using namespace std; const ll mod = 998244353; const int N = 5e5 + 10; ll a[N], n; ll ans; int main() { scanf("%lld", &n); for (int i = 1; i <= n; ++ i) { scanf("%lld", &a[i]); } sort(a + 1, a + n + 1); for (int i = 1; i <= (n >> 1); ++ i) { ans += a[i]; } ans %= mod; for (int i = (n >> 1) + 1; i <= n; ++ i) { ans = ans * a[i] % mod; } cout << ans; return 0; }