Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- #include <queue>
- #include <map>
- #include <set>
- #include <bitset>
- using namespace std;
- typedef long long ll;
- typedef double d;
- vector<bool> flag;
- struct robot{
- int a, b, c;
- };
- bool operator <(robot a, robot b){
- if(a.a == b.a){
- if(a.b == b.b){
- return a.c < b.c;
- }
- return a.b < b.b;
- }
- return a.a >= b.a;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int n;
- cin >> n;
- vector<robot> a;
- vector<int> ans(n);
- vector<robot> last;
- for(int i = 0; i < n; ++i){
- int d, w;
- cin >> d >> w;
- --d;
- a.push_back({w, d, i});
- }
- flag.resize(n, false);
- sort(a.begin(), a.end());
- //int res = 0;
- for(int i = 0; i < n; ++i){
- int m = a[i].b;
- while(flag[m] && m > -1){
- --m;
- }
- if(m < 0){
- last.push_back(a[i]);
- }
- else{
- flag[m] = true;
- ans[a[i].c] = m + 1;
- }
- }/*
- int i = 0;
- while(last.size() > 0 && i < n){
- if(!used[i]){
- ans[last[i].c] = i + 1;
- res += last[i].a;
- last.pop_back();
- }
- ++i;
- }
- cout << res << endl;
- for(int i = 0; i < ans.size(); ++i){
- cout << ans[i] << " ";
- }
- cout << endl;*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement