Joao_Joao

Worms - C++

Sep 25th, 2020 (edited)
101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;typedef long double llf;typedef double fl;typedef string str;typedef pair<double, double> dd;
  5. typedef vector<int> vi;typedef vector<vector<int>> vvi;typedef vector<fl> vf;typedef vector<ll> vl;
  6. typedef vector<llf> vlf;typedef vector<char> vc;typedef vector<str> vs;typedef pair<int,int> ii;
  7. # define f(i,a,b,c) for(ll i=a;i<b;i+=c)
  8. # define fd(i,a,b,c) for(ll i=a;i>=b;i-=c)
  9. # define ctoi(a) (a-'0')
  10. # define pb push_back
  11. # define eb emplace_back
  12. # define be(x) x.begin(), x.end()
  13. # define rbe(x) x.rbegin(), x.rend()
  14. # define _(x) ios::sync_with_stdio(0);cin.tie(0);cout.precision(x);cout.setf(ios::fixed);
  15.  
  16. const int MAX = 1e5;
  17. int n, m, au, q, ant=0, in, f, md, ns[MAX];
  18.  
  19. int main(){
  20.     cin>>n;
  21.     f(i,0,n,1)cin>>au, ns[i] = ant+au, ant += au;
  22.     cin>>m;
  23.     f(i,0,m,1){
  24.         cin>>q;
  25.         in=0, f=n-1;
  26.         while(in<f){
  27.             md = in + (f-in)/2;
  28.             if(q <= ns[md])f = md;
  29.             else in = md + 1;
  30.         }
  31.         cout<<in+1<<'\n';
  32.     }
  33. return 0;}
  34.  
  35.  
RAW Paste Data Copied