fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t;
  5. cin>>t;
  6. while(t--){
  7. int n,m;
  8. cin>>n>>m;
  9. int dish[n][2];//1st index is for day and 2nd index is for tastiness
  10. int t1, t2, d1, d2;
  11. t1=t2=d1=d2=-1;
  12. for(int i=0;i<n;i++){
  13. cin>>dish[i][0]>>dish[i][1];
  14. if(dish[i][1]>=t1){
  15. if(dish[i][0]!=d1){
  16. t2=t1;
  17. d2=d1;
  18. d1=dish[i][0];
  19. t1=dish[i][1];
  20. }
  21. else{
  22. d1=dish[i][0];
  23. t1=dish[i][1];
  24. }
  25. }
  26. else if(dish[i][1]>t2 && dish[i][0]!=d1){
  27. t2=dish[i][1];
  28. d2=dish[i][0];
  29. }
  30. }
  31. cout<<t1+t2<<endl;
  32. }
  33. return 0;
  34. }
Time limit exceeded #stdin #stdout 5s 8155136KB
stdin
Standard input is empty
stdout
Standard output is empty