#include <cstdint>
#include <cstring>
#include <map>
#include <set>
#include <utility>
using u32 = std::uint32_t;
int main()
{
u32 n, r, w, t;
std::map<int, u32> cars[2];
scanf("%u", &n);
for(u32 i=0; i<n; ++i)
{
scanf("%u %u %u", &r, &w, &t);
cars[r-1][static_cast<int>(w - t)] ++;
}
u32 result = 0;
auto x = cars[0].cbegin();
auto y = cars[1].cbegin();
const auto xend = cars[0].cend();
const auto yend = cars[1].cend();
if((x != xend) and (y != yend))
{
auto xkey = x->first;
auto ykey = y->first;
do {
if(xkey == ykey) {
result += std::min(x->second, y->second);
}
else if(xkey < ykey) {
if(++x != xend) {
xkey = x->first;
continue;
} else break;
} else {
goto INC_Y;
}
if(++x != xend) {
xkey = x->first;
} else break;
INC_Y:
if(++y != yend) {
ykey = y->first;
} else break;
} while(1);
}
printf("%u", result);
return 0;
}
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 | #include <cstdint> #include <cstring> #include <map> #include <set> #include <utility> using u32 = std::uint32_t; int main() { u32 n, r, w, t; std::map<int, u32> cars[2]; scanf("%u", &n); for(u32 i=0; i<n; ++i) { scanf("%u %u %u", &r, &w, &t); cars[r-1][static_cast<int>(w - t)] ++; } u32 result = 0; auto x = cars[0].cbegin(); auto y = cars[1].cbegin(); const auto xend = cars[0].cend(); const auto yend = cars[1].cend(); if((x != xend) and (y != yend)) { auto xkey = x->first; auto ykey = y->first; do { if(xkey == ykey) { result += std::min(x->second, y->second); } else if(xkey < ykey) { if(++x != xend) { xkey = x->first; continue; } else break; } else { goto INC_Y; } if(++x != xend) { xkey = x->first; } else break; INC_Y: if(++y != yend) { ykey = y->first; } else break; } while(1); } printf("%u", result); return 0; } |
English