ABC052B - Increment Decrement
#include <algorithm> #include <iostream> #include <string> using namespace std; #define REP(i, n) for (int i = 0; i < (n); ++i) int main(void) { int n, x = 0, max_x = 0; string s; cin.tie(0); ios::sync_with_stdio(false); cin >> n; cin >> s; REP(i, n) { x += (s[i] == 'I')? 1 : -1; max_x = max(max_x, x); } cout << (max_x < 0? 0 : max_x) << "\n"; return 0; }