Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- vector<int> A(n);
- for (int i = 0; i < n; i++) {
- cin >> A[i];
- }
- bool swapped = 1;
- while (swapped) {
- swapped = 0;
- for (int i = 0; i < n - 1; i++) {
- long long current = A[i] * (i + 1) + A[i + 1] * (i + 2);
- long long updated = A[i + 1] * (i + 1) + A[i] * (i + 2);
- if (current < updated) {
- swap(A[i], A[i + 1]);
- swapped = 1;
- }
- }
- }
- long long sum = 0;
- for (int i = 0; i < n; ++i) {
- sum += A[i] * (i + 1);
- }
- cout << sum << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement