Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#define HASAN
- #ifndef HASAN
- #include "spoj.h"
- #endif
- #include <iostream>
- #include <algorithm>
- #include <assert.h>
- using namespace std;
- #ifdef HASAN
- #define spoj_p_in finp
- #define spoj_t_out foutt
- #define spoj_p_out foutp
- #define spoj_assert assert
- #define SPOJ_RV_POSITIVE 0
- #endif
- int T;
- int arr[555];
- int perm[555];
- int n;
- int best;
- char inpt[10011011];
- bool vis[555];
- int main(){
- #ifndef HASAN
- spoj_init();
- #else
- FILE *finp = fopen("00.txt", "r");
- FILE *foutt = fopen("out.txt", "r");
- FILE *foutp = fopen("00o.txt", "r");
- #endif
- fscanf(spoj_p_in, "%d", &T);
- while(T--){
- fscanf(spoj_p_in, "%d", &n);
- for(int i=1;i<=n;i++){
- fscanf(spoj_p_in, "%d", &arr[i]);
- }
- for(int i=1;i<=n;i++){
- spoj_assert(fscanf(spoj_t_out, "%d", &perm[i])==1);
- spoj_assert(1<=perm[i] && perm[i] <= n);
- }
- for(int i=1;i<=n;i++){
- vis[i]=false;
- }
- fscanf(spoj_p_out, "%d", &best);
- for(int i=1;i<=n;i++){
- spoj_assert(!vis[perm[i]]);
- vis[perm[i]]=true;
- }
- int A=0,B=0;
- for(int i=1;i<=n;i++){
- if(A<=B){
- A += arr[perm[i]];
- } else {
- B += arr[perm[i]];
- }
- }
- spoj_assert(A == best);
- }
- spoj_assert(fscanf(spoj_t_out, "%s", inpt) != 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement