QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#10508. 最大前缀和

统计

小 C 是一个算法竞赛爱好者,有一天小 C 遇到了一个非常难的问题:求一个序列的最大子段和。

但是小 C 并不会做这个题,于是小 C 决定把序列随机打乱,然后取序列的最大前缀和作为答案。

小 C 是一个非常有自知之明的人,他知道自己的算法完全不对,所以并不关心正确率,他只关心求出的解的期望值,现在请你帮他解决这个问题,由于答案可能非常复杂,所以你只需要输出答案乘上 $n!$ 后对 $998244353$ 取模的值,显然这是个整数。

注:最大前缀和的定义:$\forall i \in [1,n]$,$\sum_{j=1}^{i}a_j$的最大值。

输入格式

第一行一个正整数 $n$,表示序列长度。

第二行 $n$ 个数,表示原序列 $a[1..n]$,第 $i$ 个数表示 $a[i]$ 。

输出格式

输出一个非负整数,表示答案。

样例数据

样例输入

2
-1 2

样例输出

3

子任务

对于$10\%$的数据,有$1\leq n\leq 9$。

对于$40\%$的数据,有$1\leq n\leq 15$。

另有$10\%$的数据,满足$a$中最多只有一个负数。

另有$10\%$的数据,满足$|a[i]|\leq 2$。

对于$100\%$的数据,满足$1\leq n\leq 20$,$\sum_{i=1}^{n}|a[i]|\leq 10^9$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.