Anyone can check my code why some test case are not passing .
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
int N,K,P;
cin>>N>>P>>K;
int r=P%K;
int move=ceil(N/(float)K);
int ans=r*move;
ans+=(P-r)/K+1;
cout<<ans<<endl;
}
return 0;
}
could you please find why below code shows runtime error: include <bits/stdc++.h> define ll long long
using namespace std;
bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
if (a.first == b.first) {
return a.second < b.second;
}
return a.first < b.first;
}
void solve() {
ll n, p, k;
cin >> n >> p >> k;
vector<pair<ll, ll>> v;
for (int i = 0; i < n; i++) {
v.push_back({i % k, i});
}
sort(v.begin(), v.end(), cmp);
ll count = 0;
for (ll i = 0; i < n; i++) {
count++;
if (v[i].second == p) {
cout << count << endl;
return; // Terminate the loop once the answer is found
}
}
}
int main() {
int t;
cin >> t;
while (t–) {
solve();
}