using namespace std;
#include <algorithm>
#include <iostream>
#include <vector>
#include <ctime>
int main() {
vector<int> arr;
srand(time(0));
int N = 10;
int min = 9999999, minIndex;
int average = 0;
for(int i = 1; i<=N; ++i) {
arr.push_back(rand());
cout << arr[i-1] << " ";
if(arr[i-1]<min) {
min = arr[i-1];
minIndex = i-1;
}
average+=arr[i-1];
cout << endl << "Min: " << min << endl << "Average: " << average/N << endl;
swap(arr[minIndex], arr[arr.size()-1]);
cout << endl << " > average: ";
if(arr[i-1]>average/N) {
using namespace std;
#include <algorithm>
#include <iostream>
#include <vector>
#include <ctime>
int main() {
vector<int> arr;
srand(time(0));
int N = 10;
int min = 9999999, minIndex;
int average = 0;
for(int i = 1; i<=N; ++i) {
arr.push_back(rand());
cout << arr[i-1] << " ";
if(arr[i-1]<min) {
min = arr[i-1];
minIndex = i-1;
}
average+=arr[i-1];
}
cout << endl << "Min: " << min << endl << "Average: " << average/N << endl;
swap(arr[minIndex], arr[arr.size()-1]);
for(int i = 1; i<=N; ++i) {
cout << arr[i-1] << " ";
}
cout << endl << " > average: ";
for(int i = 1; i<=N; ++i) {
if(arr[i-1]>average/N) {
cout << arr[i-1] << " ";
}
}
}
Это и будет наименьшее время.
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int n,i,s;
bool priz=true;
cin>>n;
int b[n],c[n];
for (int i=0; i<n; i++)
{
cin>>b[i];
c[i]=i+1;
}
// сортировка масcива по не возрастанию
while (priz)
{
priz=false;
for (int i=0; i<n-1; i++)
{
if (b[i]<b[i+1])
{
swap(b[i],b[i+1]);
swap(c[i],c[i+1]);
priz=true;
}
}
}
s=0;
for (int i=0; i<n; i++) s+=b[i]*(i+1);
cout<<s<<endl;
for (int i=0; i<n; i++) cout<<c[i]<<" ";
cout<<endl;
system("pause");
return(0);
}
Ввод - вывод:
6
10 21 13 36 41 9
332
5 4 2 3 1 6