Any one can help me please [C++]

I can’t found the wrong in this this code it does not print any thing…

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
set <int> st;
int main()
{
    int n,m,a;
    cin>>n>>m;
    int nn=n;
    while(nn--){
        cin>>a;
        st.insert(a);
    }
    set <int>::iterator it;
    it=st.end();
    it--;
    int maxk=*it+m;
    it=st.begin();
    while(m>0){
        int d=*it;
        m--;
        d++;
        st.erase(it);
        st.insert(d);
    }
    int mink=*it;
    cout<<mink<<" "<<maxk;
    return 0;
}

please use a descriptive title, it will elicit more answers, and maybe post in the correct category for the language ypu are using (#javascript #python) or specify the language you are using

also if you would more clearly describe what your code is doing and what it should be doing instead it would also much help in helping you

sorry it’s #C++ after the second while loop i’m taking the minimum number in the set and increase it by 1 in the end i just want to find what is min number in the set after “m” operation but i think there is compilation error there is mistake in the second while loop but i don’t know it

It runs for me. How are you running it (environment/compiler)? Is it compiling for you?

Ran it here
https://www.onlinegdb.com/online_c++_compiler

Make sure you have the <bits/stdc++.h> header file

1 Like