Kickstart 2021 D: Cutting Intervals, scanf vs cin

So I checking out the “Analysis” for the Cutting Intervals problem and wrote this

``````void solve(int testcase) {
ll n, c; scanf("%lld %lld", &n, &c);

map<ll, ll> m;
fo(_, 0, n) {
ll tl, tr; scanf("%lld %lld", &tl, &tr);
++m[tl+1], --m[tr];
}

// iter(x, m) printf("{%lld: %lld}, ", x.first, x.second);
// printf("\n");

map<ll, ll> a;
ll j = 0;
auto mprev = m.begin(), mcurr = ++m.begin();

while (mcurr != m.end()) {
ll kprev = mprev->first, kcurr = mcurr->first;
// printf("%lld %lld\n", kprev, kcurr);

j += mprev->second;
a[j] += kcurr - kprev;

++mprev, ++mcurr;
}

// iter(x, a) printf("{%lld: %lld}, ", x.first, x.second);
// printf("\n");

ll res = n;
for (auto it = a.rbegin(); it != a.rend(); ++it) {
res += it->first * min(it->second, c);
c -= min(it->second, c);

if (c == 0) break;
}

printf("Case #%d: %lld\n", testcase, res);
``````

}

I believe the macros are self-explanatory. This gave “Sample Failed”. However, it worked on my machine. So I sent a manual “Run Test” and the output was `Case #1: 1144119736199078559`
instead of `Case #1: 7`. But then when I switched to `cin` over `scanf` it gave AC.

Any idea why?

@ssjgz, tagging you because I have seen you answering such questions before.
(Apologies if you don’t want to be tagged like this and I’ll keep this in mind next time)

Were you using Fast input output ?

Yes! I thought it just caused `cin` and and `scanf` to be out of sync, so I made sure to only use `scanf.