Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <algorithm>
- #include <queue>
- using namespace std;
- ifstream fin("medici.in");
- ofstream fout("medici.out");
- struct coordonate
- {
- int x,y,poz;
- bool ok=false;
- } a[1001];
- int plan[1001];
- queue<pair<int,int> >q;
- bool intersectie (pair <int,int>a, pair<int,int>b)
- {
- if(a.second>=b.first && a.first<=b.second)
- {
- return false;
- }
- return true;
- }
- bool corect(coordonate a, coordonate b)
- {
- return a.y<b.y;
- }
- int main()
- {
- int n,cate=0;
- fin>>n;
- for(int i=1; i<=n; i++)
- {
- fin>>a[i].x;
- a[i].poz=i;
- }
- for(int i=1; i<=n; i++)
- {
- fin>>a[i].y;
- }
- fin.close();
- sort(a+1,a+n+1, corect);
- for(int i=1; i<=n; i++)
- {
- while(!q.empty() && intersectie(q.front(), {a[i].x, a[i].y})==false)
- {
- a[i].x=min(q.front().first, a[i].x);
- a[i].y=max(q.front().second,a[i].y);
- a[i].ok=true;
- cate+=1;
- q.pop();
- }
- q.push({a[i].x,a[i].y});
- }
- fout<<cate<<endl;
- for(int i=1; i<=n; i++)
- {
- if(a[i].ok==true)
- {
- fout<<a[i].poz<<" ";
- }
- }
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement