MAGCARI

Iguana

Oct 10th, 2022
1,140
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 1 0
  1. /*
  2.     Task    : Iguana
  3.     Author  : Phumipat C. [MAGCARI]
  4.     Language: C++
  5.     Created : 10 October 2022 [21:04]
  6. */
  7. #include<bits/stdc++.h>
  8. using namespace std;
  9. vector<pair<int ,int > > v;
  10. int main(){
  11.     int n,m,a,b;
  12.     cin >> n >> m;
  13.     for(int i=1;i<=m;i++){
  14.         cin >> a >> b;
  15.         v.push_back({a,1});
  16.         v.push_back({b+1,-1});
  17.     }
  18.     char c;
  19.     cin >> c;
  20.     int want;
  21.     if(c == 'R')        want = 0;
  22.     else if(c == 'G')   want = 1;
  23.     else                want = 2;
  24.  
  25.     v.push_back({1,0});
  26.     v.push_back({n+1,0});
  27.     sort(v.begin(),v.end());
  28.     int sum = 0,len,current,ans = 0;
  29.     for(int i=0;i<v.size()-1;i++){
  30.         sum+=v[i].second;
  31.         if(v[i].first == v[i+1].first)  continue;
  32.         current = sum%3;
  33.         len = v[i+1].first-v[i].first;
  34.         ans += ((want-current+3)%3)*len;
  35.     }
  36.     cout << ans << '\n';
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment