import java.util.Iterator; import java.util.Map; import java.util.Scanner; import java.util.TreeMap; public class M {  public static void main(String[] args)  {   Scanner sc = new Scanner(System.in);   TreeMap<Integer,Integer> map = new TreeMap<Integer,Integer>();   int sum = 0;   while(sc.hasNext())   {    int cmd = sc.nextInt();    //System.out.println(cmd);    if(cmd == 1)    {     int start = sc.nextInt();     //System.out.println(start);     int end = sc.nextInt();     //System.out.println(end);     int num = sc.nextInt();     //System.out.println(start + " " + end + " " + num);     if(start < 1)      continue;     else     {      for(int i = start; i <= end; i++)      {       if(!map.containsKey(i))       {        map.put(i,num);       }       else       {        int temp = map.get(i);        if(num > temp)         map.put(i,num);        else         continue;       }      }     }    }    else if(cmd == 2)    {     int day = sc.nextInt();     int NUM = sc.nextInt();     //System.out.println(day + " " + NUM);     if(day < 1)      continue;     else     {      if(!map.containsKey(day))       map.put(day,NUM);      else      {       int temp = map.get(day);       temp = temp + NUM;       map.put(day,temp);      }     }    }    else     break;   }   Iterator it = map.entrySet().iterator();   while(it.hasNext())   {    Map.Entry<Integer,Integer> entry = (Map.Entry<Integer, Integer>)it.next();    Integer i = entry.getValue();    sum += i;      }   if(sum <= 0)    System.out.println(0);   else       System.out.println(sum);  } }
点赞 评论

相关推荐

喜欢飞来飞去的雪碧在刷代码:可以试一试字节
点赞 评论 收藏
分享
牛客517626884号:嵌入式真难啊今年,我电赛国二都成了路边野狗了
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务