Untitled
unknown
plain_text
2 years ago
917 B
5
Indexable
#include<iostream> using namespace std; int a[1001]; int n; int ans; void sort(int index){ } int main(int argc, char** argv) { ios::sync_with_stdio(false); //freopen("input.txt", "r", stdin); int t; cin >> t; for(int tc = 1; tc <= t; tc++){ ans = 0; cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; // sort for(int i = 0; i < n-1; i++){ for(int j = i+1; j < n; j++){ if(a[i] > a[j]){ int temp = a[i]; a[i] = a[j], a[j] = temp; } } } int i = 1; while(i < n){ a[i] += a[i-1]; ans += a[i]; int j = i; while(j < n-1 && a[j] > a[j+1]){ int temp = a[j+1]; a[j+1] = a[j], a[j] = temp; j++; } //for(int k = i; k < n; k++) cout << a[k] << " "; //cout << endl; //cout << "# " << ans << endl; i++; } // print result cout << "Case #"<< tc << endl << ans << endl; } return 0; }
Editor is loading...