7 条题解
-
3凌艺樽 (lingyizun) LV 7 @ 2023-4-26 19:43:01
#include <iostream> #include <algorithm> using namespace std; int maxx=0x3f3f3f; const int N=1e3+10; int a[N] ,sum,cnt,n; int main() { cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; } sort(a+1,a+n+1); for(int i=1;i<=n;i++) { sum=sum+(a[i]+cnt); cnt+=a[i]; } cout<<sum; return 0; }
-
12023-9-10 12:05:09@
论前缀和的用处
#include <bits/stdc++.h> using namespace std; const int N=1e5+10; const int INF=0x3f3f3f3f; int a[N],s[N],ans; int main() { int n; cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; } sort(a+1,a+n+1); for(int i=1;i<=n;i++) { s[i]=a[i]+s[i-1]; ans+=s[i]; } cout<<ans; }
-
12023-4-26 19:43:40@
#include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include <algorithm> using namespace std; #define LL long long #define ull unsigned long long const int N = 1e3 + 10; const int INF = 0x3f3f3f3f; int n,a[N],cnt,sum; int main(void){ cin >> n; for (int i=1; i<=n; i++){ cin >> a[i]; } sort(a+1, a+n+1); for (int i=1; i<=n; i++){ sum=sum+(a[i]+cnt); cnt = cnt +a[i]; } cout << sum << endl; return 0; } ```
-
12023-4-15 13:40:49@
#include<iostream> using namespace std; int n,a[1001],sum; int main(){ cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) if(a[i]>a[j])swap(a[i],a[j]); for(int i=1;i<=n;i++)sum+=a[i]*(n-i+1); cout<<sum; return 0; }
-
02024-3-10 18:03:06@
#include <iostream> using namespace std; int main() { int s,t,n,a[1001]; cin >> n; for(int i = 1;i <= n;i++) cin >> a[i]; sort(a+1,a+1+n); s = t = a[1]; for(int i = 2;i <= n;i++) { s += a[i]+t; t += a[i]; } cout << s; return 0; }
-
02022-10-15 12:17:02@
#include<iostream> #include<iomanip> #include<cstring> #include<string> #include<sstream> #include<cstdio> #include<cmath> #include<cstdlib> #include<queue> #include<vector> #include<algorithm> #include<stack> #include<fstream> #include<cstdlib> #include<ctime> #include<bits/stdc++.h> #define ll long long const int N=1e5+10; const int INF=0x3f3f3f3f; using namespace std; int main(){ int n,a[1005]; scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=1;i<n;i++){ for(int j=1;j<=n-i;j++){ if(a[j]>a[j+1]){ int t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } int sum=0; for(int i=1;i<=n;i++) sum+=(n-i+1)*a[i]; printf("%d",sum); return 0; }
-
-12022-8-21 17:24:25@
#include <queue> #include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include <algorithm> using namespace std; #define LL long long #define ull unsigned long long const int N = 1e3 + 10; const int INF = 0x3f3f3f3f; int a[N]; int main() { int n; cin >> n; for(int i = 0 ; i < n ; i++) cin >> a[i]; sort(a,a+n); int ans = 0; for(int i = 0 , j = n ; i < n , j > 0 ; i++ , j--) ans += a[i] * j; cout << ans << endl; return 0; }
- 1
信息
- ID
- 1004
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 4
- 标签
- 递交数
- 431
- 已通过
- 202
- 上传者