Solve measuring-traffic

This commit is contained in:
2026-09-22 21:51:16 +01:00
parent 128448ebed
commit efafed7e91
2 changed files with 0 additions and 0 deletions
+90
View File
@@ -0,0 +1,90 @@
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
// ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout)
// ----- FOR LOOPS -----
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define FD(i,L,R) for (int i = L; i > R; i--)
#define FDE(i,L,R) for (int i = L; i >= R; i--)
// ----- WEZ -----
#define takeI(n) int (n); cin >> n
#define takeII(n,m) int (n),(m); cin >> n >> m
#define takeIII(n,m,k) int (n),(m),(k); cin >>(n) >> (m) >> (k)
// ----- MAX MIN -----
#define REMAX(a,b) (a)=max((a),(b))
#define REMIN(a,b) (a)=min((a),(b))
// ----- DEBUG -----
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
#define printV(a) printA(a,0,a.size()-1)
// ----- STL DS
#define ALL(c) (c).begin(),(c).end()
const int LARGE = 1e9;
int main() {
STDIN("traffic.in");
STDOUT("traffic.out");
takeI(n);
DBG(n);
vector<tuple<string, int, int>> segments(n);
F(i, 0, n) {
string str;
cin >> str;
takeII(l, u);
segments[i] = {str, l, u};
}
int fl = 0, fu = LARGE;
FDE(i, n-1, 0) {
string str;
int l, u;
str = get<0>(segments[i]); l = get<1>(segments[i]); u = get<2>(segments[i]);
if (str == "none") {
fl = max(fl, l);
fu = min(fu, u);
} else if (str == "on") {
fl -= l;
fu -= u;
fl = max(0, fl);
} else {
fl += l;
fu += u;
}
}
cout << fl << ' ' << fu << endl;
fl = 0, fu = LARGE;
F(i, 0, n) {
string str;
int l, u;
str = get<0>(segments[i]); l = get<1>(segments[i]); u = get<2>(segments[i]);
if (str == "none") {
fl = max(fl, l);
fu = min(fu, u);
} else if (str == "on") {
fl -= l;
fu -= u;
fl = max(0, fl);
} else {
fl += l;
fu += u;
}
}
cout << fl << ' ' << fu << endl;
}
+5
View File
@@ -0,0 +1,5 @@
4
on 1 1
none 10 14
none 11 15
off 2 3