Link to Problem:-https://cses.fi/problemset/task/1164
Code
can Someone please help me with my code..it is not working for some test cases..i have tried many test cases but could'nt find out my mistake
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Help in Cses Room Allocation Problem
Link to Problem:-https://cses.fi/problemset/task/1164
using namespace std;
bool compareBy(const pair<ll,pair<ll,int> >&a,const pair<ll ,pair<ll,int> >&b){ if(a.second.first!=b.second.first) return a.second.first<b.second.first;
return a.first<b.first;
} void solve(){ ll int n; cin>>n; vector<pair<ll,pair<ll,int> > >a;
for(int i=0;i<n;i++){ ll x,y; cin>>x>>y; a.push_back({x,{y,i}}); }
sort(a.begin(),a.end(),compareBy);
int res[n]={},valAssigned=1;
res[a[0].second.second]=valAssigned;
priority_queue<pair<int,int> ,vector<pair<int,int> >,greater<pair<int,int> > >pq;
pq.push({a[0].second.first,1}); //storing the finish time of room with the room number
for(int i=1;i<n;i++){
if(a[i].first>pq.top().first){
auto temp=pq.top().second;
pq.pop();
res[a[i].second.second]=temp;
pq.push({a[i].second.first,temp});
}
else{
res[a[i].second.second]=++valAssigned;
pq.push({a[i].second.first,valAssigned});
}
}
cout<<valAssigned<<"\n";
for(int i=0;i<n;i++)
cout<<res[i]<<" ";
cout<<endl;
}
int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t=1; // cin>>t; while(t--){ solve(); } }
can Someone please help me with my code..it is not working for some test cases..i have tried many test cases but could'nt find out my mistake
Name |
---|