welleyth

CEOI Day2 A

Sep 4th, 2021 (edited)
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.98 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. #define pb push_back
  9. #define int long long
  10. #define uint __int128
  11. #define mp make_pair
  12. #define left left_compile
  13. #define right right_compile
  14.  
  15. //#pragma GCC optimize("O3")
  16. //#pragma GCC optimize("unroll-loops")
  17.  
  18. const int INF = (int)1e18;
  19. const int md = (int)1e9 + 7;
  20. const int MAXN = (int)100;
  21. const int N = (int)4e6 + 111;
  22. //const int L = 20;
  23. const int debug = 0;
  24. const long double eps = 1e-7;
  25.  
  26. //typedef tree<
  27. //int,
  28. //null_type,
  29. //less_equal<int>,
  30. //rb_tree_tag,
  31. //tree_order_statistics_node_update>
  32. //ordered_set;
  33.  
  34. int bpow(int a,int b){
  35.     if(b == 0)
  36.         return 1ll;
  37.     if(b % 2 == 0){
  38.         int t = bpow(a,b/2);
  39.         return (t * t) % md;
  40.     }
  41.     return (a * bpow(a,b-1)) % md;
  42. }
  43.  
  44. int inv(int a){ /// return 1/a by PRIME modulo md
  45.     return bpow(a,md-2);
  46. }
  47.  
  48. //void myerase(ordered_set& st, int t){
  49. //    int r = st.order_of_key(t);
  50. //    ordered_set::iterator it = st.find_by_order(r);
  51. //    st.erase(it);
  52. //    return;
  53. //}
  54.  
  55. mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
  56.  
  57. void init(){
  58.     return;
  59. }
  60.  
  61. int n,m;
  62.  
  63. void add(int& a,int b){
  64.     a += b;
  65.     if(a >= m)
  66.         a -= m;
  67.     return;
  68. }
  69.  
  70. void sub(int& a,int b){
  71.     a -= b;
  72.     if(a < 0)
  73.         a += m;
  74.     return;
  75. }
  76.  
  77. void solve_case(){
  78.     int n;
  79.     cin >> n;
  80.  
  81.     int a[n+1];
  82.     a[0] = 0;
  83.  
  84.     int sum = 0;
  85.     int cnt = 0;
  86.     for(int i = 1; i <= n; i++){
  87.         cin >> a[i];
  88.         cnt += (a[i] == 1);
  89.         sum += a[i];
  90.     }
  91.  
  92.     int number = n;
  93.     while(number > 0){
  94.         int id;
  95.         cin >> id;
  96.         if(sum == a[id]){
  97.             cout << a[id] << "\n";
  98.             cout << "-1\n";
  99.             number--;
  100.             sum -= a[id];
  101.             return;
  102.         }
  103.         if(a[id] == 1){
  104.             cout << "1\n";
  105.             number--;
  106.             sum--;
  107.             a[id] = 0;
  108.             for(int i = 1; i <= n; i++){
  109.                 if(a[i] == 1){
  110.                     cout << i << "\n";
  111.                     int x;
  112.                     cin >> x;
  113.                     a[i] -= x;
  114.                     number--;
  115.                     sum--;
  116.                     break;
  117.                 }
  118.             }
  119.             continue;
  120.         }
  121.         cout << a[id] - 1 << "\n";
  122.         cout << id << "\n";
  123.         sum -= a[id] - 1;
  124.         a[id] -= a[id] - 1;
  125.         int x;
  126.         cin >> x;
  127.         sum -= x;
  128.         number--;
  129.     }
  130.  
  131.     cout << "-1\n";
  132.  
  133.     return;
  134. }
  135.  
  136. signed main(){
  137. //    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  138. //    freopen("internship.in","r",stdin);
  139. //    freopen("internship.out","w",stdout);
  140.  
  141. //    init();
  142.  
  143.     int tests = 1;
  144. //    cin >> tests;
  145.  
  146.     for(int _ = 1; _ <= tests; _++){
  147.         solve_case();
  148.     }
  149.  
  150.     return 0;
  151. }
  152.  
  153. /*
  154.  
  155. 4 <=> 100
  156. 7 <=> 111
  157. 3 <=> 011
  158.  
  159.  
  160. 0100
  161. 0111
  162.  
  163. 0100
  164. 0101
  165.  
  166.  
  167. */
  168.  
Add Comment
Please, Sign In to add comment