#include<bits/stdc++.h>
using namespace std;
int main(){
int N, K;
cin >> N;
cin >> K;
vector<int> seq;
for(int i = 0; i < N; i++){
int temp;
cin >> temp;
seq.push_back(temp);
}
for (int pass = 0; pass < K; pass++) {
bool swapped = false;
for (int j = 0; j < N - pass - 1; j++) {
if (seq[j] > seq[j + 1]) {
swap(seq[j], seq[j + 1]);
swapped = true;
}
}
// If no elements were swapped, the array is sorted
if (!swapped) break;
}
for(int ll = 0; ll < N; ll++){
cout << seq[ll] << " ";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |