zoukankan      html  css  js  c++  java
  • Doing Homework again

     Doing Homework again
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
    Submit Status

    Description

    Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test. And now we assume that doing everyone homework always takes one day. So Ignatius wants you to help him to arrange the order of doing homework to minimize the reduced score.
     

    Input

    The input contains several test cases. The first line of the input is a single integer T that is the number of test cases. T test cases follow.
    Each test case start with a positive integer N(1<=N<=1000) which indicate the number of homework.. Then 2 lines follow. The first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the reduced scores.
     

    Output

    For each test case, you should output the smallest total reduced score, one line per test case.
     

    Sample Input

    3
    3
    3 3 3
    10 5 1
    3
    1 3 1
    6 2 3
    7
    1 4 6 4 2 4 3
    3 2 1 7 6 5 4
     

    Sample Output

    0
    3
    5
     
     
     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <map>
     5 #include <algorithm>
     6 using namespace std;
     7 typedef struct abcd
     8 {
     9     int w,l;
    10 }abcd;
    11 abcd a[1200];
    12 bool cmp(abcd x,abcd y)
    13 {
    14     if(x.w==y.w)return x.l>y.l;
    15     return x.w>y.w;
    16 }
    17 map<int,int> m;
    18 int main()
    19 {
    20     int t,n,i,j,ans;
    21     scanf("%d",&t);
    22     while(t--)
    23     {
    24         scanf("%d",&n);
    25         for(i=0;i<n;i++)
    26         scanf("%d",&a[i].l);
    27         for(i=0;i<n;i++)
    28         scanf("%d",&a[i].w);
    29         sort(a,a+n,cmp);
    30         m.clear();
    31         ans=0;
    32         for(i=0;i<n;i++)
    33         {
    34             if(m[a[i].l]==0)
    35             {
    36                 m[a[i].l]=1;
    37             }
    38             else
    39             {
    40                 while(a[i].l>0&&m[a[i].l])a[i].l--;
    41                 if(a[i].l>0)m[a[i].l]=1;
    42                 else ans+=a[i].w;
    43             }
    44         }
    45         cout<<ans<<endl;
    46     }
    47 }
    View Code
     
     
     
  • 相关阅读:
    mysql group_concat函数
    easyui textbox获取焦点事件
    jquery获取select下拉框的前一个,后一个,第一个,最后一个option对象
    easyui 只刷新当前页面的数据 datagrid reload 方法
    spring-data-jpa查询语句的书写实例小计
    jquery给input标签添加data-options属性
    正则表达式的常用方法
    正则表达式之 /^(d)$/
    jquery获取下拉列表的值和显示内容的方法
    一个 关于 case when的SQL
  • 原文地址:https://www.cnblogs.com/ERKE/p/3842038.html
Copyright © 2011-2022 走看看