How to calculate Time Complexity

How To Calculate time complexity of below code(Problem - 682A - Codeforces)
See below My code.
My code is correct but i want to calculate the time complexity and How
Please Explain in detail.

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
#define lli long long int
#define vi vector<lli>
#define Q queue<lli>
#define vii vector<pair<lli,lli> >
#define pb push_back
#include<string>
#define mp map<string,lli>
#define mpp map<char,lli>
#define MPP map<lli,lli>
#define ss set<lli>
#define S set<char>
#define MOD 1000000007
#define test lli t;cin>>t;while(t--)
using namespace std;
const int MAX=1e5+3;
int main()
{
    lli n,m;
    cin>>n>>m;
    vi arr;
    MPP a;
    for(lli i=1;i<=m;i++)
        a[i%5]+=1;
    lli sum=0;
    for(lli i=1;i<=n;i++)
       {
           lli rem=(i%5);
           if(rem==0)
            sum+=a[rem];
           else
           sum+=a[5-rem];
       }
    cout<<sum<<endl;
}

O(m+n) in worst case.

The time complexity is O((M+N) * Log S) where S is maximum size of map
Log S is there as you are using Map
M is there as the first loop runs M times
N is there as the second loop runs N times

2 Likes