fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n,g;
  4. int s[10000000];
  5. int ss[10000000];//
  6. int id[10000000];
  7. int ans[10000000];
  8. int main() {
  9. ios_base::sync_with_stdio(false);
  10. cin.tie(0); cout.tie(0);
  11. cin>>n>>g;
  12. for(int i=0;i<n;i++){
  13. cin >> s[i];
  14. }
  15. iota( id,id+n,0 );
  16. sort( id,id+n,[]( int rhs,int lhs ){
  17. return s[rhs] < s[lhs];
  18. });
  19.  
  20. for(int i=0;i<g;i++){
  21. int a,b,la=n,sm=-1;
  22. cin>>a>>b;
  23. for(int j=0;j<n;j++){
  24.  
  25. if( a>s[ id[j] ]){
  26. //cout<<j<<" ";
  27. sm=j;
  28. }
  29. if( b<s[ id[j] ] ){
  30. //cout<<" ("<<j<<") ";
  31. la=j;
  32. break;
  33. }
  34. }
  35. if(la-sm-1!=0){
  36. cout<<la-sm-1<<"\n";
  37. continue;
  38. }
  39. cout<<"The candies are too short"<<"\n";
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 7696KB
stdin
5 3
2 3 7 9 0
2 6
2 8
1 1
stdout
2
3
The candies are too short