Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : Iguana
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 10 October 2022 [21:04]
- */
- #include<bits/stdc++.h>
- using namespace std;
- vector<pair<int ,int > > v;
- int main(){
- int n,m,a,b;
- cin >> n >> m;
- for(int i=1;i<=m;i++){
- cin >> a >> b;
- v.push_back({a,1});
- v.push_back({b+1,-1});
- }
- char c;
- cin >> c;
- int want;
- if(c == 'R') want = 0;
- else if(c == 'G') want = 1;
- else want = 2;
- v.push_back({1,0});
- v.push_back({n+1,0});
- sort(v.begin(),v.end());
- int sum = 0,len,current,ans = 0;
- for(int i=0;i<v.size()-1;i++){
- sum+=v[i].second;
- if(v[i].first == v[i+1].first) continue;
- current = sum%3;
- len = v[i+1].first-v[i].first;
- ans += ((want-current+3)%3)*len;
- }
- cout << ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment