Master Openjudge, the master was taken by the monster.

Source: Internet
Author: User

Describe

Monkey King heard drifting shouted: "Master brother, Master was taken by the devil!" So the Monkey King went straight after the bones. Monkey King in a length of the forest on the path of the small road, above the l+1 on the whole point, in turn, 0,1,2 ... L Bones Jing will use a wide range of attack spells, producing n energy spheres, where the energy value of the I energy sphere is f[i] and falls on the whole point of the path k[i]. When the Sun Wukong's position is s from the energy ball I, it will be affected by f[i]-s, if the damage calculated by f[i]-s is negative, then it is determined to be 0. Although the Monkey King is eager to save the teacher, but also can not be buried in the spell of Bones Jing, so he wants to know where to hide on the whole point, in order to let himself suffer the least total damage.

Enter line 1th: 2 positive integers l,n (1≤l≤2,000,1≤n≤2,000) 2nd line: n integers, number of I represents energy ball placement coordinates k[i] (0≤k[i]≤l) 3rd line: n integers, number I indicates the energy value of the energy sphere numbered I f[ I] (1≤f[i]≤10,000) output line 1th: An integer that represents the coordinates of the minimum total damage, and if there are multiple coordinates to obtain the minimum value, the output of the smallest coordinate. Line 2nd: An integer that represents the value of the smallest total damage sample input

4 31 4 210 5 7

Sample output

015



Openjudge

Mother Egg Today, Beijing University School Hang This topic I altogether not carefully see the topic so water is not the state AH main my dad came to Beijing to see me so water ...
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include < map> #include <stack> #include <queue> #include <cmath> #define INF 1000000000 using name    Space Std;    int k[2005];    int f[2005];    int Min_l,min_shanghai;        int main () {int l,n;        int S2;        scanf ("%d%d", &l,&n);        for (int i=1;i<=n;i++) scanf ("%d", &k[i]);        for (int i=1;i<=n;i++) scanf ("%d", &f[i]);        Min_shanghai=inf;            for (int i=0;i<=l;i++) {s2=0;            for (int j=1;j<=n;j++) {if (F[j]-abs (k[j]-i) >0) s2+=f[j]-abs (k[j]-i);                } if (S2<min_shanghai) {min_l=i;            MIN_SHANGHAI=S2;            }} printf ("%d\n", min_l);        printf ("%d\n", Min_shanghai);    return 0; }

Openjudge Master, Master was taken by the monster.

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.