-
Notifications
You must be signed in to change notification settings - Fork 0
/
A_Free_Ice_Cream.cpp
229 lines (211 loc) · 4.97 KB
/
A_Free_Ice_Cream.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/**
* Author: Ashfak Hossain Evan, American International University, Bangladesh
* Created: 13/06/2023 18:40:31
**/
#include <bits/stdc++.h>
#define rep(i, L, R) for (int i = L; i < R; i++)
#define rep1(i, L, R) for (int i = L; i <= R; i++)
#define rrep(i, L, R) for (int i = L; i > R; i--)
#define rrep1(i, L, R) for (int i = L; i >= R; i--)
#define range(a, b) for (auto &(a) : (b))
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define char2Int(c) (c - '0')
#define lastEle(vec) vec[vec.size() - 1]
#define PI 3.1415926535897932384626433832795l
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;
string to_upper(string a)
{
for (int i = 0; i < (int)a.size(); ++i)
if (a[i] >= 'a' && a[i] <= 'z')
a[i] -= 'a' - 'A';
return a;
}
string to_lower(string a)
{
for (int i = 0; i < (int)a.size(); ++i)
if (a[i] >= 'A' && a[i] <= 'Z')
a[i] += 'a' - 'A';
return a;
}
bool prime(ll a)
{
if (a == 1)
return 0;
for (int i = 2; i <= round(sqrt(a)); ++i)
if (a % i == 0)
return 0;
return 1;
}
/* Debug Code */
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename A>
void __print(const A &x);
template <typename A, typename B>
void __print(const pair<A, B> &p);
template <typename... A>
void __print(const tuple<A...> &t);
template <typename T>
void __print(stack<T> s);
template <typename T>
void __print(queue<T> q);
template <typename T, typename... U>
void __print(priority_queue<T, U...> q);
template <typename A>
void __print(const A &x)
{
bool first = true;
cerr << '{';
for (const auto &i : x)
{
cerr << (first ? "" : ","), __print(i);
first = false;
}
cerr << '}';
}
template <typename A, typename B>
void __print(const pair<A, B> &p)
{
cerr << '(';
__print(p.first);
cerr << ',';
__print(p.second);
cerr << ')';
}
template <typename... A>
void __print(const tuple<A...> &t)
{
bool first = true;
cerr << '(';
apply([&first](const auto &...args)
{ ((cerr << (first ? "" : ","), __print(args), first = false), ...); },
t);
cerr << ')';
}
template <typename T>
void __print(stack<T> s)
{
vector<T> debugVector;
while (!s.empty())
{
T t = s.top();
debugVector.push_back(t);
s.pop();
}
reverse(debugVector.begin(), debugVector.end());
__print(debugVector);
}
template <typename T>
void __print(queue<T> q)
{
vector<T> debugVector;
while (!q.empty())
{
T t = q.front();
debugVector.push_back(t);
q.pop();
}
__print(debugVector);
}
template <typename T, typename... U>
void __print(priority_queue<T, U...> q)
{
vector<T> debugVector;
while (!q.empty())
{
T t = q.top();
debugVector.push_back(t);
q.pop();
}
__print(debugVector);
}
void _print() { cerr << "]\n"; }
template <typename Head, typename... Tail>
void _print(const Head &H, const Tail &...T)
{
__print(H);
if (sizeof...(T))
cerr << ", ";
_print(T...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
void solve()
{
ll n, x;
cin >> n >> x;
ll distres(0);
for (ll i = 0; i < n; i++)
{
char a;
ll b;
cin >> a >> b;
if (a == '-' && b <= x)
{
x -= b;
}
else if (a == '+')
{
x += b;
}
else
{
distres++;
}
}
cout << x << " " << distres << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif*/
int tc(1);
// cin >> tc;
rep1(t, 1, tc)
{
// cout << "Case #" << t << ": ";
solve();
}
// cerr << "Time elapsed : " << (float)clock() / CLOCKS_PER_SEC << " s" << endl;
return 0;
}