Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <algorithm>
- #include <vector>
- #define InFile "cioc.in"
- #define OutFile "cioc.out"
- using namespace std;
- vector<int> a;
- bool myfunction(int i,int j)
- {
- return (i<j);
- }
- int main()
- {
- int c,n,k,x;
- ifstream f(InFile);
- f>>c>>n>>k;
- for(int i=0;i<n;++i)
- f>>x,a.push_back(x);
- f.close();
- random_shuffle(a.begin(),a.end());
- nth_element(a.begin(),a.begin()+k,a.end(),myfunction);
- nth_element(a.begin(),a.begin()+k,a.end());
- ofstream g(OutFile);
- if(c==1)
- {
- g<<k;
- }
- else
- {
- for(vector<int> ::iterator it=a.begin();it!=a.end();++it)
- g<<*it<<' ';
- g<< '\n';
- }
- g.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement