It a nice solution, and it also explains that we were thinking this problem the wrong way the entire time.
It a nice solution, and it also explains that we were thinking this problem the wrong way the entire time.
Its good, I've already seen their Free tutorials. They have more of a practical approach, but they have less conceptual knowledge. I find CommonLounge much more comprehensive and understandable rather than just copy pasting.
The solution would be right if we only had to print the id numbers, We also have to print the total no. before printing the id's.
So you have to store each value in array then print its size and each element which is more memory consuming. Map/dictionary approach is not just simple, its also optimum.
#include <iostream>#include <map>using namespace std;int main() {int n1,n2,n3;cin>>n1>>n2>>n3;map<int,int> m;int x;for(int i=0;i<n1+n2+n3;i++){cin>>x;m[x]++;}int count=0;
This is more optimum than the easy solution. In this solution, I don't have to calculate the cumulative sum for both players. I am just calculating the cumulative difference that is lead. If diff is positive p1 wins else p2 wins. Max lead will be the max |diff|.
#include <iostream>#include <cmath>using namespace std;int main() {int max=0,diff=0,w;int t,p1,p2;cin>>t;while(t--){cin>>p1>>p2;diff+=(p1-p2);int abs=fabs(diff);if(abs>max){if(diff>0)w=1;elsew=2;max=abs;
But I didn't got all those correct, so how do I get to know where was my mistake?