comparison between Array and Map

I am doing a code force problem link: http://codeforces.com/problemset/problem/600/B

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
#include <bits/stdc++.h>

using namespace std;
typedef map<int,int>::iterator it;

int main(int argc, char** argv) {
    vector <int>y;//main
	map<int,int>first;
    int f,s;//f is the length of the first array 
			//s is the length of the second array 
    int total=0;
    int num;
    
    cin>>f;
    cin>>s;
    
    for(int i = 0; i < f;i++){
        cin>>num;
        first[num]++;//used to increment the value ... will be used later to speed up the process
    }
    for(int i=0; i < s;i++){
        cin>>num;
        y.push_back(num);
    }
    for(int i=0;i<s;i++){
        for(it j=first.begin();j!=first.end();j++){
            if(y[i] < (j->first) || y[i] == j->first){
                total++;
            }
        cout<<total<<" ";
        total=0;
    }
    cout<<endl;
    return 0;
}


is there a problem with comparing if(y[i] < (j->first) || y[i] == j->first) because the total comes back to me wrong.
Last edited on
If some value is entered 100 times and you only increase total once for it, is that going to be accurate?

(You'd be better off referring to the documentation on std::upper_bound and using two vectors than using a map.)
Topic archived. No new replies allowed.