不管行列   总是先切割切割费用大的  代码比较烂 ......

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
bool cmp(int a, int b)
{
return a > b;
}
int a[1010],b[1010];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int m,n;
scanf("%d%d",&m,&n);
for(int i = 0; i < m-1; i++)
{
scanf("%d",&a[i]);
}
for(int i = 0; i < n-1; i++)
{
scanf("%d",&b[i]);
}
sort(a, a+m-1, cmp);
sort(b, b+n-1, cmp);
int sum = 0;
int p,q;
p = q = 0;
while(p != m-1 || q != n-1)
{
if(p != m-1 && q != n-1 && a[p] >= b[q])
{
sum += a[p];
for(int j = q; j < n-1; j++)
{
sum += b[j];
}
p++;
}
else if(p != m-1 && q != n-1 && a[p] < b[q])
{
sum += b[q];
for(int j = p; j < m-1; j++)
{
sum += a[j];
}
q++;
}
else if(p == m-1)
{
for(int j = q; j < n-1; j++)
{
sum += b[j];
}
q = n-1;
}
else
{
for(int j = p; j < m-1; j++)
{
sum += a[j];
}
p = m-1;
}
}
printf("%d\n",sum);
}
return 0;
}

spoj 247的更多相关文章

  1. SPOJ 247 chocolate (CHOCLO)

    题目http://www.spoj.com/problems/CHOCOLA/ 把一整块巧克力分成一个一个单元,掰断每一横行有个代价值,掰断每个纵行也有个代价值,要你求最后的总代价值最小 这个题目放在 ...

  2. BZOJ 2588: Spoj 10628. Count on a tree [树上主席树]

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 5217  Solved: 1233 ...

  3. SPOJ DQUERY D-query(主席树)

    题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ...

  4. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  5. 【填坑向】spoj COT/bzoj2588 Count on a tree

    这题是学主席树的时候就想写的,,, 但是当时没写(懒) 现在来填坑 = =日常调半天lca(考虑以后背板) 主席树还是蛮好写的,但是代码出现重复,不太好,导致调试的时候心里没底(虽然事实证明主席树部分 ...

  6. SPOJ bsubstr

    题目大意:给你一个长度为n的字符串,求出所有不同长度的字符串出现的最大次数. n<=250000 如:abaaa 输出: 4 2 1 1 1 spoj上的时限卡的太严,必须使用O(N)的算法那才 ...

  7. 【SPOJ 7258】Lexicographical Substring Search

    http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和 ...

  8. 【SPOJ 1812】Longest Common Substring II

    http://www.spoj.com/problems/LCS2/ 这道题想了好久. 做法是对第一个串建后缀自动机,然后用后面的串去匹配它,并在走过的状态上记录走到这个状态时的最长距离.每匹配完一个 ...

  9. 【SPOJ 8222】Substrings

    http://www.spoj.com/problems/NSUBSTR/ clj课件里的例题 用结构体+指针写完模板后发现要访问所有的节点,改成数组会更方便些..于是改成了数组... 这道题重点是求 ...

随机推荐

  1. HDOJ2014青年歌手大奖赛_评委会打分

    青年歌手大奖赛_评委会打分 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  2. ios app名字的多语言支持

    经测试,不同版本的xcode会有操作细节不同,本次环境xcode6.4 1)编辑Info.plist,添加一个新的属性Application has localized display name, 设 ...

  3. python - 图例显示中文

    # -*- coding: utf-8 -*- """ Created on Mon Nov 30 13:24:00 2015 @author: jx_luo " ...

  4. Cocos2d-x实例:设置背景音乐与音效-HelloWorld场景实现

    HelloWorld场景就是游戏中的主菜单场景.HelloWorld.h文件代码如下: #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h& ...

  5. 关于FPGA(verilog)电平检测模块的易错点分析

    reg F1,F2; // F2 Previous State, F1 Current State always@(posedge CLK or negedge RSTn) if(!RSTn) beg ...

  6. jvmstat监控jvm内存

    1.下载jvmstat-3_0.zip: 2.配置环境变量JVMSTAT_JAVA_HOME为jdk目录E:\Program Files\Java\jdk1.5.0_12 3.监控本机:  jps查看 ...

  7. [zz]pg_hba.conf 一种安全地配置策略

    PostgreSQL默认只监听本地端口,用netstat -tuln只会看到“tcp 127.0.0.1:5432 LISTEN”.修改postgresql.conf中的listen_address= ...

  8. From MSI to WiX, Part 8 - Major Upgrade, by Alex Shevchuk

    Following content is reprinted from here, please go to the original website for more information. Au ...

  9. 编译安装php Cannot find MySQL header files under /usr/include/mysql.

    编译php-5.5-6的mysql支持,出现Cannot find MySQL header files under /usr/include/mysql. Note that the MySQL c ...

  10. SQL Server如何使用XML格式传输解析

    Sqlserver in 实现 参数化查询 XML类型解决方案 [转] :如果参数是int类型: declare @a xml set @a=' <row><id>1</ ...