2 条题解
-
012209水宇辰 (12209水宇辰) LV 9 @ 2021-12-24 19:15:59
#pragma GCC optimize(2) #pragma GCC optimize(3) #include <cstdio> #include <vector> #include <cstring> #include <iostream> #include <algorithm> #include <functional> using namespace std; typedef long long ll; vector<int> a, b, v; int n; int main() { scanf("%d", &n); for ( int i = 0; i < n; i ++ ) { int x; scanf("%d", &x); v.push_back(x); } int m; scanf("%d", &m); for ( int i = 0; i < m; i ++ ) { int x; scanf("%d", &x); v.push_back(x); } sort(v.begin(), v.end(), greater<int>()); for ( int i = 0; i < m + n; i ++ ) { if ( !(i % 2) ) a.push_back(v[i]); else b.push_back(v[i]); } sort(b.begin(), b.end()); sort(a.begin(), a.end(), greater<int>()); ll res = 0; int time = 1; for (int i = 0; i < a.size(); i ++, time ++ ) res += a[i] * time; for (int i = 0; i < b.size(); i ++, time ++ ) res += b[i] * time; printf("%d", res); return 0; }
-
02021-11-01 21:57:35@
#pragma GCC optimize(2) #pragma GCC optimize(3) #include <cstdio> #include <vector> #include <cstring> #include <iostream> #include <algorithm> #include <functional> using namespace std; typedef long long ll; vector<int> a, b, v; int n; int main() { scanf("%d", &n); for ( int i = 0; i < n; i ++ ) { int x; scanf("%d", &x); v.push_back(x); } int m; scanf("%d", &m); for ( int i = 0; i < m; i ++ ) { int x; scanf("%d", &x); v.push_back(x); } sort(v.begin(), v.end(), greater<int>()); for ( int i = 0; i < m + n; i ++ ) { if ( !(i % 2) ) a.push_back(v[i]); else b.push_back(v[i]); } sort(b.begin(), b.end()); sort(a.begin(), a.end(), greater<int>()); ll res = 0; int time = 1; for (int i = 0; i < a.size(); i ++, time ++ ) res += a[i] * time; for (int i = 0; i < b.size(); i ++, time ++ ) res += b[i] * time; printf("%d", res); return 0; }
- 1
信息
- ID
- 2425
- 难度
- 3
- 分类
- (无)
- 标签
- 递交数
- 49
- 已通过
- 27
- 通过率
- 55%
- 被复制
- 2
- 上传者