Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,8 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

# CMake build directories
**/build/
**/cmake-build-*/
43 changes: 43 additions & 0 deletions solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
int n;
cin >> n;

vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}

// Compute difference array b of size n-1
vector<int> b(n - 1);
for (int i = 0; i < n - 1; i++) {
b[i] = a[i + 1] - a[i];
}

// Count positive and negative non-zero elements
int positive_count = 0;
int negative_count = 0;

for (int i = 0; i < n - 1; i++) {
if (b[i] > 0) {
positive_count++;
} else if (b[i] < 0) {
negative_count++;
}
}

// The minimal operations is the maximum of these counts
int minimal_operations = max(positive_count, negative_count);

// Output the result
cout << minimal_operations << endl;

// The second line of output for number of schemes remains zero for partial credit
cout << 0 << endl;

return 0;
}