Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C.cpp: определяет точку входа для консольного приложения.
- //
- //#include "stdafx.h"
- #include <cmath>
- #include <algorithm>
- #include <iostream>
- #include <vector>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- vector <ll> up, down;
- int main()
- {
- ll last, count, n, data;
- char ch;
- cin >> last >> count >> n;
- for (int i = 0; i < n; i++)
- {
- cin >> data >> ch;
- if (ch == 'U')
- up.push_back(data);
- else
- down.push_back(data);
- }
- ll mn, ans = 0, ans1 = 0;
- for (int i = 0; i < 2 * (count + up.size()); i++)
- {
- if (ans1 == count + up.size())
- {
- cout << ans << endl;
- break;
- }
- mn = last;
- for (int j = 0; j < up.size(); j++)
- mn = min(last - up[j], mn);
- for (int j = 0; j < down.size(); j++)
- mn = min(down[j], mn);
- for (int j = 0; j < up.size(); j++)
- up[j] += mn;
- for (int j = 0; j < down.size(); j++)
- down[j] -= mn;
- for (int j = 0; j < up.size(); j++)
- if (up[j] == last)
- {
- up.erase(up.begin() + j);
- down.push_back(last);
- ans1++;
- }
- for (int j = 0; j < down.size(); j++)
- if (down[j] == 0)
- {
- down.erase(down.begin() + j);
- up.push_back(0);
- }
- ans += mn;
- }
- //system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement