+ 1

Where am i making the mistake? Help please

Tina and Rahul have 1toy each. They are entering into an amusement park but it is not allowed to take the toys inside, so they have to keep it in the boxes provided by the park management. They want to keep the toys together in one box. There are N boxes in total, at this moment there are t(i) toys present in (i)th box and the maximum capacity of the box is denoted by c(i). Rahul and Tina want to know in how many boxes can they keep their toys such that both the toys are in the same box. Input- 4 (count boxes) 1 2 2 4 5 6 6 10 Output 2 My code-#include <iostream> using namespace std; int main() { int n; cin>>n; int x,y; for(int i=1; i<=n; i++) { cin>>x>>y; int c,count; count=0; while(i<n) { c= y-x; if(c/2>=1) count++; } cout<<count<<endl; } return 0; }

10th Aug 2020, 12:03 PM
Navneet Chauhan
Navneet Chauhan - avatar
2 ответов
0
Here both have to store the toy In a same box, there diff and divison by 2 must be greater than 1. #include <bits/stdc++.h> using namespace std; int main() { //write your code here int n,a,b,c=0; scanf("%d",&n); while(n-->0){ scanf("%d %d",&a,&b); if ((b-a)/2>=1){ c=c+1; } } printf("%d",c); return 0; }
31st Aug 2020, 7:33 AM
Ravi Kumar
Ravi Kumar - avatar