7 solutions
-
0
将打水的人按从小到大排序,然后思路就很清晰了 样例:3 6 1 4 2 5 7 1 2 3 4 5 6 7 第一个人0,第二个1,第三个3,第四个6,第五个10,第六个15,第七个21 #include #include using namespace std; long long int n,sum; int s[100005],a[100005]; int main() { cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; } sort(a,a+n); for(int i=0;i<n;i++) { sum+=a[i]*(n-i-1); } cout<<sum; return 0; }
Information
- ID
- 76
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 251
- Accepted
- 78
- Uploaded By