Codeforces Goodbye C

Source: Internet
Author: User

/** *  @brief  good bye 2014 c *  @file  c.cpp *  @author  mianma *  @created  2014/01/06  16:42 *  @edited   2014/01/06   16:42 *  @type  game *  @note   */#include  <fstream># include <iostream> #include  <cstring> #include  <vector> #include  <set > #include  <stack> #include  <algorithm>using namespace std; #define &NBSP;MAX (A ,  b)    ((a)  >  (b)  ?  (a)  :  (b)) #define &NBSP;MIN (a, b)     ((a)  >  (b)  ?  (b)  :  (a))   #define &NBSP;ABS (a)        ((a)  >  0  ?  (a)  :  (0 -  (a))) #define &NBSP;CLR (VEC)    memset (vec, 0, sizeof (VEC)) #ifdef  DEBUGifstream in;ofstream  Out; #define  cin in#define &NBSP;COUT&NBSP;OUT#ELSE#DEFINE&NBSP;CIN&NBSP;CIN#DEFINE&NBSP;COUT&NBSP;COUT#ENDIF#DEFINE&NBSP;MAXN  1010typedef long long int ll;int table[maxn];    /*value &NBSP;TABLE*/INT&NBSP;MV[MAXN];&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;/*MOVE&NBSP;TABLE*/INT&NBSP;VEC[MAXN] ;       /*build stack*/int cnt;int ans;int main (void) {     int n, m, tmp;    ios_base::sync_with_stdio (0); #ifdef  debug    cin.open ("./in",   ios::in);     cout.open ("./ Out ",   ios::out); #endif     CIN >> n >> m;     for (int i = 1; i <= n; i++)          cin >> table[i];    for (int i = 1;  i <= m; i++) {        int newone = 1;         cin >> tmp;        mv[i]  = tmp;        for (int j = 0; j  < cnt; j++) {            if ( tmp &NBSP;==&NBSP;VEC[J]) {                 newone = 0;                 break;            }         }          if ( Newone)             vec[cnt++] = tmp;     }    for (int i = 1; i <= m; i++) {         int idx = mv[i];        for (int  j = 0; j < cnt; j++) {                 if (VEC[J]&NBSP;==&NBSP;IDX) {                          for (int k = j - 1; k >= 0; k--) {                              ans += table[vec[k]];                              vec[k + 1] = vec[k];                         }        &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;VEC[0]  = idx;                         break;                 }        }     }    COUT << ans <<  "\ n";     return 0;}


Codeforces Goodbye C

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.