Codeforces 474B Worms (water problem, two points)

Source: Internet
Author: User

Test instructions: Given the number of n heaps, then there are M-words to ask you in which heap.

Analysis: This problem is a two-part problem, but there is a function, can replace write two points, Lower_bound.

The code is as follows:

#include <bits/stdc++.h>using namespace Std;typedef long long ll;const int MAXN = 1e5 + 5;int a[maxn];int main () {
  
   int N, M;    CIN >> N;    for (int i = 1; I <= n; ++i)  scanf ("%d", &a[i]);    for (int i = 2; I <= n; ++i) a[i] + = a[i-1];    Cin >> m;    int x;    while (m--) {        scanf ("%d", &x);        int t = Lower_bound (A, a+n, X)-A;        printf ("%d\n", t);    }    return 0;}
  

Codeforces 474B Worms (water problem, two points)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.