Untitled
plain_text
2 months ago
675 B
1
Indexable
Never
#include <iostream> using namespace std; int main(){ freopen("input.txt","r",stdin); int T,x; cin>>T; for (x = 0; x < T; x++){ int N,i; cin>>N; int S[1000]; for (i = 0; i < N; i++) cin>>S[i]; int j; for (i = 0; i < N-1; i++) for (j = i +1; j < N; j++){ if (S[j]<S[i]){ int t = S[j]; S[j] = S[i]; S[i] = t; } } i = 1; int time = 0; while (i < N){ S[i] = S[i] + S[i-1]; time = time + S[i]; int j = i; while (j < N -1 && S[j] > S[j+1]){ int t = S[j+1]; S[j+1] = S[j]; S[j] = t; j++; } i++; } cout << "Case #"<<x+1<<endl<<time<<endl; } return 0; }