I wrote a program for problem 318A on CodeForces. It seems to work fine for small numbers as input (when n = 7 and k = 1, or when n = 8 and k = 4, etc..). However, if n and k are large numbers (for example, n = 1000000000000 and k = 500000000001), then I get a MEMORY_LIMIT_EXCEEDED error.
I'm not sure how to fix this. I tried to turn the variables from int to long long int, but that didn't work. I think the problem is that the loop can't cope with large numbers.
This was my submission:
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<int>v,v2;
int n,k;
cin >> n >> k;
for (int i=1; i<=n;i+=2){
v.push_back(i);
v2.push_back(i+1);
}
v.insert(v.end(),v2.begin(),v2.end());
cout << v[k-1];
}