#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n{};
cin >> n;
vector<int>dostawy1{};
vector<int>dostawy2{};
for (int i = 0; i < n; i++)
{
int r{}, w{}, t{};
cin >> r >> w >> t;
if (r == 1) dostawy1.push_back(w-t);
else dostawy2.push_back(w-t);
}
sort(dostawy1.begin(), dostawy1.end());
sort(dostawy2.begin(), dostawy2.end());
int liczba = dostawy1[0];
int ilosc{};
int odp{};
for (int i = 0; i < dostawy1.size()+1; i++)
{
if(i < dostawy1.size() && dostawy1[i] == liczba)
{
ilosc++;
}else
{
int num = count(dostawy2.begin(), dostawy2.end(), liczba);
odp += min(num, ilosc);
liczba = dostawy1[i];
ilosc = 1;
}
}
cout << odp << "\n";
}
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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n{}; cin >> n; vector<int>dostawy1{}; vector<int>dostawy2{}; for (int i = 0; i < n; i++) { int r{}, w{}, t{}; cin >> r >> w >> t; if (r == 1) dostawy1.push_back(w-t); else dostawy2.push_back(w-t); } sort(dostawy1.begin(), dostawy1.end()); sort(dostawy2.begin(), dostawy2.end()); int liczba = dostawy1[0]; int ilosc{}; int odp{}; for (int i = 0; i < dostawy1.size()+1; i++) { if(i < dostawy1.size() && dostawy1[i] == liczba) { ilosc++; }else { int num = count(dostawy2.begin(), dostawy2.end(), liczba); odp += min(num, ilosc); liczba = dostawy1[i]; ilosc = 1; } } cout << odp << "\n"; } |
English