fork download
  1. //Coded by Vishal Mourya
  2. //If you use this code anywhere you need to mention my name as above
  3.  
  4. #include<bits/stdc++.h>
  5. #define ll long long int
  6. #define fe(a,b) for( ll i = a ; i <= b; i++ )
  7. #define fasthoja ios_base::sync_with_stdio(false); cin.tie(NULL);
  8.  
  9. using namespace std;
  10.  
  11. void solve() {
  12. ll t; cin >> t;
  13. while(t--) {
  14. ll a; cin >> a; //The choice input of cup or cone
  15. ll n; cin >> n; //number of scoops
  16. ll cost = 0;
  17.  
  18. //find total cost
  19. if( a == 1 ) cost += 7; //cup
  20. else cost += 10; //cone
  21.  
  22. fe(1,n) {
  23. ll f; cin >> f; //Flavour of scoop
  24. switch(f){
  25. case 1: //Strawberry
  26. cost += 30;
  27. break;
  28. case 2: //Vanilla
  29. cost += 20;
  30. break;
  31. case 3: //Mango
  32. cost += 30;
  33. break;
  34. case 4: //Oreo
  35. cost += 50;
  36. break;
  37. case 5: //Chocolate
  38. cost += 40;
  39. break;
  40. }
  41. }//end of for loop
  42.  
  43. if( n > 3 ){//as number of scoops cannot exceed 3
  44. cout << "Invalid Entry\n";
  45. continue;
  46. }
  47. cout << cost << "\n";
  48. }//end of test case loop
  49. }
  50.  
  51. int main(void) {
  52.  
  53. fasthoja;
  54. solve();
  55. return 0;
  56. }
Success #stdin #stdout 0s 4552KB
stdin
2
1
3
2 2 4
2
4
1 2 3 4
stdout
97
Invalid Entry