Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
999 B
5
Indexable
#include <iostream>
#include <climits>
#include <set>

using namespace std;

int main() {
    int size;
    cin >> size;
    int a[size];
    int inv;
    int minInd = 0;
    
    
    for (int i = 0;i < size; i++) {
        cin >> a[i];
        
        if (a[i] < a[minInd]) {
            minInd = i;
        }
    }
    
    int mini = INT_MAX;
    int i = 0;
    
    while (i < size) {
        if (a[i] > a[minInd]) {
            inv++;
            
            if (a[i] < mini) {
                mini = a[i];
            }
        }
        
        if (i == minInd) {
            int currInd = i+1;
            minInd = i+1;
            for (int j = i+1; j < size; j++) {
                if (a[j] < a[minInd]) {
                    minInd = j;
                }
            }
            
           int i = currInd; 
        }
        
        if (i == size-1 && a[i] > mini) {
            inv++;
        }
        
        i++;
    }
    
    
    
    cout << inv << endl;

    return 0;
}
Leave a Comment