#include <iostream>
//#include <chrono>
//using namespace std::chrono;
using namespace std;
int main()
{
long n, tab[2000000][2], r, w, t, ret, i;
// auto start = high_resolution_clock::now();
for (i = 0; i < 2000000; i++)
tab[i][0] = tab[i][1] = 0;
ret = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> r >> w >> t;
if (r == 1) {
if (tab[w - t + 1000000][1] > 0) {
tab[w - t + 1000000][1]--;
ret++;
}
else tab[w - t + 1000000][0] ++;
}
else {
if (tab[w - t + 1000000][0] > 0) {
tab[w - t + 1000000][0]--;
ret++;
}
else tab[w - t + 1000000][1] ++;
}
}
// for (i = 0; i < 200000; i++)
// ret += (tab[i][0] < tab[i][1] ? tab[i][0] : tab[i][1]);
cout << ret;
// auto stop = high_resolution_clock::now();
// auto duration = duration_cast<microseconds>(stop - start);
// cout << "Timer=" << duration.count() << endl;
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 | #include <iostream> //#include <chrono> //using namespace std::chrono; using namespace std; int main() { long n, tab[2000000][2], r, w, t, ret, i; // auto start = high_resolution_clock::now(); for (i = 0; i < 2000000; i++) tab[i][0] = tab[i][1] = 0; ret = 0; cin >> n; for (i = 0; i < n; i++) { cin >> r >> w >> t; if (r == 1) { if (tab[w - t + 1000000][1] > 0) { tab[w - t + 1000000][1]--; ret++; } else tab[w - t + 1000000][0] ++; } else { if (tab[w - t + 1000000][0] > 0) { tab[w - t + 1000000][0]--; ret++; } else tab[w - t + 1000000][1] ++; } } // for (i = 0; i < 200000; i++) // ret += (tab[i][0] < tab[i][1] ? tab[i][0] : tab[i][1]); cout << ret; // auto stop = high_resolution_clock::now(); // auto duration = duration_cast<microseconds>(stop - start); // cout << "Timer=" << duration.count() << endl; return 0; } |
English