Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. //#define HASAN
  2.  
  3. #ifndef HASAN
  4. #include "spoj.h"
  5. #endif
  6.  
  7. #include <iostream>
  8. #include <algorithm>
  9. #include <assert.h>
  10. using namespace std;
  11.  
  12.  
  13. #ifdef HASAN
  14. #define spoj_p_in finp
  15. #define spoj_t_out foutt
  16. #define spoj_p_out foutp
  17. #define spoj_assert assert
  18. #define SPOJ_RV_POSITIVE 0
  19. #endif
  20.  
  21. int T;
  22. int arr[555];
  23. int perm[555];
  24. int n;
  25. int best;
  26. char inpt[10011011];
  27. bool vis[555];
  28. int main(){
  29. #ifndef HASAN
  30. spoj_init();
  31. #else
  32. FILE *finp = fopen("00.txt", "r");
  33. FILE *foutt = fopen("out.txt", "r");
  34. FILE *foutp = fopen("00o.txt", "r");
  35. #endif
  36. fscanf(spoj_p_in, "%d", &T);
  37. while(T--){
  38. fscanf(spoj_p_in, "%d", &n);
  39. for(int i=1;i<=n;i++){
  40. fscanf(spoj_p_in, "%d", &arr[i]);
  41. }
  42. for(int i=1;i<=n;i++){
  43. spoj_assert(fscanf(spoj_t_out, "%d", &perm[i])==1);
  44. spoj_assert(1<=perm[i] && perm[i] <= n);
  45. }
  46. for(int i=1;i<=n;i++){
  47. vis[i]=false;
  48. }
  49. fscanf(spoj_p_out, "%d", &best);
  50.  
  51. for(int i=1;i<=n;i++){
  52. spoj_assert(!vis[perm[i]]);
  53. vis[perm[i]]=true;
  54. }
  55. int A=0,B=0;
  56. for(int i=1;i<=n;i++){
  57. if(A<=B){
  58. A += arr[perm[i]];
  59. } else {
  60. B += arr[perm[i]];
  61. }
  62. }
  63.  
  64. spoj_assert(A == best);
  65. }
  66. spoj_assert(fscanf(spoj_t_out, "%s", inpt) != 1);
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement