How do i solve the memory exceeded problem here according to my code? problem no:318 A Even and odds sub id: 128562778 code:
include
include
include
include
include<bits/stdc++.h>
using namespace std; int main() { int n; int k;
cin>>n>>k;
vector v1; vector v2;
for(int i=1;i<=n;i++) { if(i%2!=0) { v1.push_back(i); } else if(i%2==0) { v2.push_back(i); } } int len1=v1.size();
if(k<=len1) cout<<v1[k-1]; else if(k>len1) cout<<v2[k-5];
}
The maximum size of array or vector you could possibly take is 10^6 — 10^7 and the value is n is atmost 10^12 so you can't store that many elements that in an array or vector.